Commit 8f3aa6ac authored by Lin Jen-Shin's avatar Lin Jen-Shin

Try to check if branch diverged explicitly

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_21627134
parent d475fa09
......@@ -82,12 +82,7 @@ class GitOperationService
end
branch = repository.find_branch(branch_name)
oldrev = if branch
# This could verify we're not losing commits
repository.rugged.merge_base(newrev, branch.target)
else
Gitlab::Git::BLANK_SHA
end
oldrev = find_oldrev_from_branch(newrev, branch)
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
update_ref_in_hooks(ref, newrev, oldrev)
......@@ -100,6 +95,18 @@ class GitOperationService
newrev
end
def find_oldrev_from_branch(newrev, branch)
return Gitlab::Git::BLANK_SHA unless branch
oldrev = branch.target
if oldrev == repository.rugged.merge_base(newrev, branch.target)
oldrev
else
raise Repository::CommitError.new('Branch diverged')
end
end
def update_ref_in_hooks(ref, newrev, oldrev)
with_hooks(ref, newrev, oldrev) do
update_ref(ref, newrev, oldrev)
......
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