Commit 3c7e94f4 authored by Stan Hu's avatar Stan Hu

Merge branch 'ce-to-ee-2018-09-10' into 'master'

CE upstream - 2018-09-10 21:21 UTC

Closes gitlab-ce#50003 and #7471

See merge request gitlab-org/gitlab-ee!7313
parents aa30d5fb e48c95ae
...@@ -6,3 +6,4 @@ danger.import_dangerfile(path: 'danger/gemfile') ...@@ -6,3 +6,4 @@ danger.import_dangerfile(path: 'danger/gemfile')
danger.import_dangerfile(path: 'danger/database') danger.import_dangerfile(path: 'danger/database')
danger.import_dangerfile(path: 'danger/documentation') danger.import_dangerfile(path: 'danger/documentation')
danger.import_dangerfile(path: 'danger/frozen_string') danger.import_dangerfile(path: 'danger/frozen_string')
danger.import_dangerfile(path: 'danger/commit_messages')
...@@ -180,7 +180,7 @@ gem 'state_machines-activerecord', '~> 0.5.1' ...@@ -180,7 +180,7 @@ gem 'state_machines-activerecord', '~> 0.5.1'
gem 'acts-as-taggable-on', '~> 5.0' gem 'acts-as-taggable-on', '~> 5.0'
# Background jobs # Background jobs
gem 'sidekiq', '~> 5.1' gem 'sidekiq', '~> 5.2.1'
gem 'sidekiq-cron', '~> 0.6.0' gem 'sidekiq-cron', '~> 0.6.0'
gem 'redis-namespace', '~> 1.6.0' gem 'redis-namespace', '~> 1.6.0'
gem 'sidekiq-limit_fetch', '~> 3.4', require: false gem 'sidekiq-limit_fetch', '~> 3.4', require: false
......
...@@ -141,7 +141,7 @@ GEM ...@@ -141,7 +141,7 @@ GEM
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
concurrent-ruby-ext (1.0.5) concurrent-ruby-ext (1.0.5)
concurrent-ruby (= 1.0.5) concurrent-ruby (= 1.0.5)
connection_pool (2.2.1) connection_pool (2.2.2)
crack (0.4.3) crack (0.4.3)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
crass (1.0.4) crass (1.0.4)
...@@ -678,7 +678,7 @@ GEM ...@@ -678,7 +678,7 @@ GEM
httpclient (>= 2.4) httpclient (>= 2.4)
multi_json (>= 1.3.6) multi_json (>= 1.3.6)
rack (>= 1.1) rack (>= 1.1)
rack-protection (2.0.1) rack-protection (2.0.3)
rack rack
rack-proxy (0.6.0) rack-proxy (0.6.0)
rack rack
...@@ -872,9 +872,8 @@ GEM ...@@ -872,9 +872,8 @@ GEM
rack rack
shoulda-matchers (3.1.2) shoulda-matchers (3.1.2)
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
sidekiq (5.1.3) sidekiq (5.2.1)
concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.2)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0) rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5) redis (>= 3.3.5, < 5)
sidekiq-cron (0.6.0) sidekiq-cron (0.6.0)
...@@ -1203,7 +1202,7 @@ DEPENDENCIES ...@@ -1203,7 +1202,7 @@ DEPENDENCIES
settingslogic (~> 2.0.9) settingslogic (~> 2.0.9)
sham_rack (~> 1.3.6) sham_rack (~> 1.3.6)
shoulda-matchers (~> 3.1.2) shoulda-matchers (~> 3.1.2)
sidekiq (~> 5.1) sidekiq (~> 5.2.1)
sidekiq-cron (~> 0.6.0) sidekiq-cron (~> 0.6.0)
sidekiq-limit_fetch (~> 3.4) sidekiq-limit_fetch (~> 3.4)
simple_po_parser (~> 1.1.2) simple_po_parser (~> 1.1.2)
......
...@@ -144,7 +144,7 @@ GEM ...@@ -144,7 +144,7 @@ GEM
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
concurrent-ruby-ext (1.0.5) concurrent-ruby-ext (1.0.5)
concurrent-ruby (= 1.0.5) concurrent-ruby (= 1.0.5)
connection_pool (2.2.1) connection_pool (2.2.2)
crack (0.4.3) crack (0.4.3)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
crass (1.0.4) crass (1.0.4)
...@@ -682,7 +682,7 @@ GEM ...@@ -682,7 +682,7 @@ GEM
httpclient (>= 2.4) httpclient (>= 2.4)
multi_json (>= 1.3.6) multi_json (>= 1.3.6)
rack (>= 1.1) rack (>= 1.1)
rack-protection (2.0.1) rack-protection (2.0.3)
rack rack
rack-proxy (0.6.0) rack-proxy (0.6.0)
rack rack
...@@ -880,9 +880,8 @@ GEM ...@@ -880,9 +880,8 @@ GEM
rack rack
shoulda-matchers (3.1.2) shoulda-matchers (3.1.2)
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
sidekiq (5.1.3) sidekiq (5.2.1)
concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.2)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0) rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5) redis (>= 3.3.5, < 5)
sidekiq-cron (0.6.0) sidekiq-cron (0.6.0)
...@@ -1213,7 +1212,7 @@ DEPENDENCIES ...@@ -1213,7 +1212,7 @@ DEPENDENCIES
settingslogic (~> 2.0.9) settingslogic (~> 2.0.9)
sham_rack (~> 1.3.6) sham_rack (~> 1.3.6)
shoulda-matchers (~> 3.1.2) shoulda-matchers (~> 3.1.2)
sidekiq (~> 5.1) sidekiq (~> 5.2.1)
sidekiq-cron (~> 0.6.0) sidekiq-cron (~> 0.6.0)
sidekiq-limit_fetch (~> 3.4) sidekiq-limit_fetch (~> 3.4)
simple_po_parser (~> 1.1.2) simple_po_parser (~> 1.1.2)
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
.line_holder td { .line_holder td {
line-height: $code-line-height; line-height: $code-line-height;
font-size: $code-font-size; font-size: $code-font-size;
vertical-align: top;
&.noteable_line { &.noteable_line {
position: relative; position: relative;
......
...@@ -2075,6 +2075,12 @@ class Project < ActiveRecord::Base ...@@ -2075,6 +2075,12 @@ class Project < ActiveRecord::Base
auto_cancel_pending_pipelines == 'enabled' auto_cancel_pending_pipelines == 'enabled'
end end
# Update the default branch querying the remote to determine its HEAD
def update_root_ref(remote_name)
root_ref = repository.find_remote_root_ref(remote_name)
change_head(root_ref) if root_ref.present? && root_ref != default_branch
end
private private
def rename_or_migrate_repository! def rename_or_migrate_repository!
......
...@@ -29,6 +29,7 @@ class Repository ...@@ -29,6 +29,7 @@ class Repository
delegate :ref_name_for_sha, to: :raw_repository delegate :ref_name_for_sha, to: :raw_repository
delegate :bundle_to_disk, to: :raw_repository delegate :bundle_to_disk, to: :raw_repository
delegate :find_remote_root_ref, to: :raw_repository
CreateTreeError = Class.new(StandardError) CreateTreeError = Class.new(StandardError)
......
...@@ -5,13 +5,14 @@ module Projects ...@@ -5,13 +5,14 @@ module Projects
attr_reader :errors attr_reader :errors
def execute(remote_mirror) def execute(remote_mirror)
@errors = []
return success unless remote_mirror.enabled? return success unless remote_mirror.enabled?
errors = []
begin begin
remote_mirror.ensure_remote! remote_mirror.ensure_remote!
repository.fetch_remote(remote_mirror.remote_name, no_tags: true) repository.fetch_remote(remote_mirror.remote_name, no_tags: true)
project.update_root_ref(remote_mirror.remote_name)
opts = {} opts = {}
if remote_mirror.only_protected_branches? if remote_mirror.only_protected_branches?
......
---
title: Fix vertical alignment of text in diffs
merge_request: 21573
author:
type: fixed
---
title: Synchronize the default branch when updating a remote mirror
merge_request: 21653
author:
type: fixed
---
title: Bump KaTeX version to 0.9.0
merge_request: 21625
author:
type: fixed
# frozen_string_literal: true
# rubocop: disable Style/SignalException
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/PerceivedComplexity
# Perform various checks against commits. We're not using
# https://github.com/jonallured/danger-commit_lint because its output is not
# very helpful, and it doesn't offer the means of ignoring merge commits.
def fail_commit(commit, message)
fail("#{commit.sha}: #{message}")
end
def lines_changed_in_commit(commit)
commit.diff_parent.stats[:total][:lines]
end
def subject_starts_with_capital?(subject)
first_char = subject.chars.first
first_char.upcase == first_char
end
def ce_upstream?
gitlab.mr_labels.any? { |label| label == 'CE upstream' }
end
def lint_commits(commits)
failures = false
unicode_emoji_regex = %r((
[\u{1F300}-\u{1F5FF}] |
[\u{1F1E6}-\u{1F1FF}] |
[\u{2700}-\u{27BF}] |
[\u{1F900}-\u{1F9FF}] |
[\u{1F600}-\u{1F64F}] |
[\u{1F680}-\u{1F6FF}] |
[\u{2600}-\u{26FF}]
))x
commits.each do |commit|
# For now we'll ignore merge commits, as getting rid of those is a problem
# separate from enforcing good commit messages.
next if commit.message.start_with?('Merge branch')
subject, separator, details = commit.message.split("\n", 3)
if subject.split.length < 3
fail_commit(
commit,
'The commit subject must contain at least three words'
)
failures = true
end
if subject.length > 50
fail_commit(
commit,
'The commit subject may not be longer than 50 characters'
)
failures = true
end
unless subject_starts_with_capital?(subject)
fail_commit(commit, 'The commit subject must start with a capital letter')
failures = true
end
if subject.end_with?('.')
fail_commit(commit, 'The commit subject must not end with a period')
failures = true
end
if separator && !separator.empty?
fail_commit(
commit,
'The commit subject and body must be separated by a blank line'
)
failures = true
end
details&.each_line do |line|
line = line.strip
next if line.length <= 72
url_size = line.scan(%r((https?://\S+))).sum { |(url)| url.length }
# If the line includes a URL, we'll allow it to exceed 72 characters, but
# only if the line _without_ the URL does not exceed this limit.
next if line.length - url_size <= 72
fail_commit(
commit,
'The commit body should not contain more than 72 characters per line'
)
failures = true
end
if !details && lines_changed_in_commit(commit) >= 20
fail_commit(
commit,
'Commits that change more than 20 lines ' \
'must describe these changes in the commit body'
)
failures = true
end
if commit.message.match?(/:[\+a-z0-9_\-]+:/)
fail_commit(
commit,
'Avoid the use of Markdown Emoji such as `:+1:`. ' \
'These add no value to the commit message, ' \
'and are displayed as plain text outside of GitLab'
)
failures = true
end
if commit.message.match?(unicode_emoji_regex)
fail_commit(
commit,
'Avoid the use of Unicode Emoji. ' \
'These add no value to the commit message, ' \
'and may not be displayed properly everywhere'
)
failures = true
end
if commit.message.match?(%r(([\w\-\/]+)?(#|!|&|%)\d+))
fail_commit(
commit,
'Use full URLs instead of short references ' \
'(`gitlab-org/gitlab-ce#123` or `!123`), as short references are ' \
'displayed as plain text outside of GitLab'
)
failures = true
end
end
if failures
markdown(<<~MARKDOWN)
## Commit message standards
One or more commit messages do not meet our Git commit message standards.
For more information on how to write a good commit message, take a look at
[How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/).
Here is an example of a good commit message:
Reject ruby interpolation in externalized strings
When using ruby interpolation in externalized strings, they can't be
detected. Which means they will never be presented to be translated.
To mix variables into translations we need to use `sprintf`
instead.
Instead of:
_("Hello \#{subject}")
Use:
_("Hello %{subject}) % { subject: 'world' }
This is an example of a bad commit message:
updated README.md
This commit message is bad because although it tells us that README.md is
updated, it doesn't tell us why or how it was updated.
MARKDOWN
end
end
if git.commits.length > 10 && !ce_upstream?
warn(
'This merge request includes more than 10 commits. ' \
'Please rebase these commits into a smaller number of commits.'
)
else
lint_commits(git.commits)
end
...@@ -40,6 +40,8 @@ module Importers ...@@ -40,6 +40,8 @@ module Importers
end end
def execute def execute
PrometheusMetric.reset_column_information
process_content do |id, attributes| process_content do |id, attributes|
find_or_build_metric!(id) find_or_build_metric!(id)
.update!(**attributes) .update!(**attributes)
......
...@@ -4298,6 +4298,40 @@ describe Project do ...@@ -4298,6 +4298,40 @@ describe Project do
end end
end end
describe '#update_root_ref' do
let(:project) { create(:project, :repository) }
it 'updates the default branch when HEAD has changed' do
stub_find_remote_root_ref(project, ref: 'feature')
expect { project.update_root_ref('origin') }
.to change { project.default_branch }
.from('master')
.to('feature')
end
it 'does not update the default branch when HEAD does not change' do
stub_find_remote_root_ref(project, ref: 'master')
expect { project.update_root_ref('origin') }
.not_to change { project.default_branch }
end
it 'does not update the default branch when HEAD does not exist' do
stub_find_remote_root_ref(project, ref: 'foo')
expect { project.update_root_ref('origin') }
.not_to change { project.default_branch }
end
def stub_find_remote_root_ref(project, ref:)
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('origin')
.and_return(ref)
end
end
def rugged_config def rugged_config
Gitlab::GitalyClient::StorageSettings.allow_disk_access do Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.rugged.config project.repository.rugged.config
......
require 'spec_helper' require 'spec_helper'
describe Projects::UpdateRemoteMirrorService do describe Projects::UpdateRemoteMirrorService do
set(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:owner) { project.owner }
let(:remote_project) { create(:forked_project_with_submodules) } let(:remote_project) { create(:forked_project_with_submodules) }
let(:repository) { project.repository }
let(:raw_repository) { repository.raw }
let(:remote_mirror) { project.remote_mirrors.create!(url: remote_project.http_url_to_repo, enabled: true, only_protected_branches: false) } let(:remote_mirror) { project.remote_mirrors.create!(url: remote_project.http_url_to_repo, enabled: true, only_protected_branches: false) }
let(:remote_name) { remote_mirror.remote_name }
subject { described_class.new(project, project.creator) } subject(:service) { described_class.new(project, project.creator) }
describe "#execute" do describe "#execute" do
before do before do
repository.add_branch(owner, 'existing-branch', 'master') project.repository.add_branch(project.owner, 'existing-branch', 'master')
allow(remote_mirror).to receive(:update_repository).and_return(true) allow(remote_mirror).to receive(:update_repository).and_return(true)
end end
it "ensures the remote exists" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
expect(remote_mirror).to receive(:ensure_remote!)
service.execute(remote_mirror)
end
it "fetches the remote repository" do it "fetches the remote repository" do
expect(remote_mirror).to receive(:ensure_remote!).and_call_original stub_find_remote_root_ref(project, remote_name: remote_name)
expect(repository).to receive(:fetch_remote).with(remote_mirror.remote_name, no_tags: true) do
sync_remote(repository, remote_mirror.remote_name, local_branch_names) expect(project.repository)
end .to receive(:fetch_remote)
.with(remote_mirror.remote_name, no_tags: true)
service.execute(remote_mirror)
end
it "updates the default branch when HEAD has changed" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name, ref: "existing-branch")
subject.execute(remote_mirror) expect { service.execute(remote_mirror) }
.to change { project.default_branch }
.from("master")
.to("existing-branch")
end end
it "succeeds" do it "does not update the default branch when HEAD does not change" do
allow(repository).to receive(:fetch_remote) { sync_remote(repository, remote_mirror.remote_name, local_branch_names) } stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name, ref: "master")
expect { service.execute(remote_mirror) }.not_to change { project.default_branch }
end
result = subject.execute(remote_mirror) it "returns success when updated succeeds" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
result = service.execute(remote_mirror)
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
end end
context 'when syncing all branches' do context 'when syncing all branches' do
it "push all the branches the first time" do it "push all the branches the first time" do
allow(repository).to receive(:fetch_remote) stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
expect(remote_mirror).to receive(:update_repository).with({}) expect(remote_mirror).to receive(:update_repository).with({})
subject.execute(remote_mirror) service.execute(remote_mirror)
end end
end end
context 'when only syncing protected branches' do context 'when only syncing protected branches' do
let(:unprotected_branch_name) { 'existing-branch' } it "sync updated protected branches" do
let(:protected_branch_name) do stub_fetch_remote(project, remote_name: remote_name)
project.repository.branch_names.find { |n| n != unprotected_branch_name } stub_find_remote_root_ref(project, remote_name: remote_name)
end protected_branch = create_protected_branch(project)
let!(:protected_branch) do
create(:protected_branch, project: project, name: protected_branch_name)
end
before do
project.reload
remote_mirror.only_protected_branches = true remote_mirror.only_protected_branches = true
end
it "sync updated protected branches" do expect(remote_mirror)
allow(repository).to receive(:fetch_remote) .to receive(:update_repository)
expect(remote_mirror).to receive(:update_repository).with(only_branches_matching: [protected_branch_name]) .with(only_branches_matching: [protected_branch.name])
subject.execute(remote_mirror) service.execute(remote_mirror)
end end
end
end
def sync_remote(repository, remote_name, local_branch_names) def create_protected_branch(project)
local_branch_names.each do |branch| branch_name = project.repository.branch_names.find { |n| n != 'existing-branch' }
commit = repository.commit(branch) create(:protected_branch, project: project, name: branch_name)
repository.write_ref("refs/remotes/#{remote_name}/#{branch}", commit.id) if commit end
end end
end end
def update_remote_branch(repository, remote_name, branch) def stub_find_remote_root_ref(project, ref: 'master', remote_name:)
masterrev = repository.commit('master').id allow(project.repository)
.to receive(:find_remote_root_ref)
repository.write_ref("refs/remotes/#{remote_name}/#{branch}", masterrev, force: true) .with(remote_name)
repository.expire_branches_cache .and_return(ref)
end end
def update_branch(repository, branch) def stub_fetch_remote(project, remote_name:)
masterrev = repository.commit('master').id allow(project.repository)
.to receive(:fetch_remote)
repository.write_ref("refs/heads/#{branch}", masterrev, force: true) .with(remote_name, no_tags: true) { fetch_remote(project.repository, remote_name) }
repository.expire_branches_cache
end end
def generate_tags(repository, *tag_names) def fetch_remote(repository, remote_name)
tag_names.each_with_object([]) do |name, tags| local_branch_names(repository).each do |branch|
tag = repository.find_tag(name) commit = repository.commit(branch)
target = tag.try(:target) repository.write_ref("refs/remotes/#{remote_name}/#{branch}", commit.id) if commit
target_commit = tag.try(:dereferenced_target)
tags << Gitlab::Git::Tag.new(repository.raw_repository, {
name: name,
target: target,
target_commit: target_commit
})
end end
end end
def local_branch_names def local_branch_names(repository)
branch_names = repository.branches.map(&:name) branch_names = repository.branches.map(&:name)
# we want the protected branch to be pushed first # we want the protected branch to be pushed first
branch_names.unshift(branch_names.delete('master')) branch_names.unshift(branch_names.delete('master'))
......
...@@ -4273,11 +4273,11 @@ karma@^3.0.0: ...@@ -4273,11 +4273,11 @@ karma@^3.0.0:
tmp "0.0.33" tmp "0.0.33"
useragent "2.2.1" useragent "2.2.1"
katex@^0.8.3: katex@^0.9.0:
version "0.8.3" version "0.9.0"
resolved "https://registry.yarnpkg.com/katex/-/katex-0.8.3.tgz#909d99864baf964c3ccae39c4a99a8e0fb9a1bd0" resolved "https://registry.yarnpkg.com/katex/-/katex-0.9.0.tgz#26a7d082c21d53725422d2d71da9b2d8455fbd4a"
dependencies: dependencies:
match-at "^0.1.0" match-at "^0.1.1"
keyv@3.0.0: keyv@3.0.0:
version "3.0.0" version "3.0.0"
...@@ -4534,7 +4534,7 @@ marked@^0.3.12: ...@@ -4534,7 +4534,7 @@ marked@^0.3.12:
version "0.3.12" version "0.3.12"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.12.tgz#7cf25ff2252632f3fe2406bde258e94eee927519" resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.12.tgz#7cf25ff2252632f3fe2406bde258e94eee927519"
match-at@^0.1.0: match-at@^0.1.1:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.1.tgz#25d040d291777704d5e6556bbb79230ec2de0540" resolved "https://registry.yarnpkg.com/match-at/-/match-at-0.1.1.tgz#25d040d291777704d5e6556bbb79230ec2de0540"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment