Skip to content
Snippets Groups Projects
Commit 8f3aa6ac authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Try to check if branch diverged explicitly

parent d475fa09
No related branches found
No related tags found
No related merge requests found
Loading
@@ -82,12 +82,7 @@ class GitOperationService
Loading
@@ -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)
Loading
@@ -100,6 +95,18 @@ class GitOperationService
Loading
@@ -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)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment