Try to check if branch diverged explicitly
Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_21627134
This commit is contained in:
parent
d475fa0946
commit
8f3aa6ac33
|
@ -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
|
||||||
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…
Reference in New Issue