Commit 707f6abd authored by Robert Speicher's avatar Robert Speicher

Merge branch 'mirror-default-branch' into 'master'

Show warning when mirror repository default branch could not be
updated because it has diverged from upstream.

Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/223

See merge request !138
parents 256aedff b918cd50
v 8.5.0 (unreleased)
- Show warning when mirror repository default branch could not be updated because it has diverged from upstream.
v 8.4.2
- Elasticsearch indexer performance improvements
......
......@@ -26,6 +26,8 @@ module Projects
def update_branches
local_branches = repository.branches.each_with_object({}) { |branch, branches| branches[branch.name] = branch }
errors = []
repository.upstream_branches.each do |upstream_branch|
name = upstream_branch.name
......@@ -34,20 +36,27 @@ module Projects
if local_branch.nil?
result = CreateBranchService.new(project, current_user).execute(name, upstream_branch.target)
if result[:status] == :error
raise UpdateError, result[:message]
errors << result[:message]
end
elsif local_branch.target == upstream_branch.target
# Already up to date
elsif repository.diverged_from_upstream?(name)
# Cannot be updated
if name == project.default_branch
errors << "The default branch (#{project.default_branch}) has diverged from its upstream counterpart and could not be updated automatically."
end
else
begin
repository.ff_merge(current_user, upstream_branch.target, name)
rescue GitHooksService::PreReceiveError, Repository::CommitError => e
raise UpdateError, e.message
errors << e.message
end
end
end
unless errors.empty?
raise UpdateError, errors.join("\n\n")
end
end
def update_tags(&block)
......
......@@ -20,9 +20,7 @@
protected
- if @project.mirror_ever_updated_successfully? && @repository.diverged_from_upstream?(branch.name)
- tooltip_message = "The branch could not be updated automatically because it has diverged from its upstream counterpart."
- tooltip_message << "<br>To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above." if can?(current_user, :push_code, @project)
%span.label.label-danger.has_tooltip{data: { html: "true", title: tooltip_message }}
%span.label.label-danger.has_tooltip{data: { html: "true", title: branch_diverged_tooltip_message }}
= icon('exclamation-triangle')
diverged from upstream
......
......@@ -8,3 +8,8 @@
This project is mirrored from #{link_to import_url, import_url}.
= render "shared/mirror_status"
- if @ref.present? && @project.mirror_ever_updated_successfully? && @repository.diverged_from_upstream?(@ref)
%span.has_tooltip{data: { html: "true", title: branch_diverged_tooltip_message }}
= icon('exclamation-triangle')
This branch has diverged from upstream.
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