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 ...@@ -82,12 +82,7 @@ class GitOperationService
end end
branch = repository.find_branch(branch_name) branch = repository.find_branch(branch_name)
oldrev = if branch oldrev = find_oldrev_from_branch(newrev, branch)
# This could verify we're not losing commits
repository.rugged.merge_base(newrev, branch.target)
else
Gitlab::Git::BLANK_SHA
end
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
update_ref_in_hooks(ref, newrev, oldrev) update_ref_in_hooks(ref, newrev, oldrev)
...@@ -100,6 +95,18 @@ class GitOperationService ...@@ -100,6 +95,18 @@ class GitOperationService
newrev newrev
end 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) def update_ref_in_hooks(ref, newrev, oldrev)
with_hooks(ref, newrev, oldrev) do with_hooks(ref, newrev, oldrev) do
update_ref(ref, newrev, oldrev) 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