Commit 4c4889da authored by Douwe Maan's avatar Douwe Maan

Show warning when mirror repository default branch could not be updated...

Show warning when mirror repository default branch could not be updated because it has diverged from upstream.
parent aa2f58eb
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.1
- No EE-specific changes
......
......@@ -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