diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-01-26 21:59:12 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-01-26 21:59:12 +0800 |
commit | 8f3aa6ac338ee3595909fea9938611fb03187e6a (patch) | |
tree | 7b7ccf8d85f0cf33249c384b5ae76d7d78b03741 | |
parent | d475fa094689a6319fa60f2532898234979e30d3 (diff) | |
download | gitlab-ce-8f3aa6ac338ee3595909fea9938611fb03187e6a.tar.gz |
Try to check if branch diverged explicitly
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_21627134
-rw-r--r-- | app/services/git_operation_service.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb index df9c393844d..27bcc047601 100644 --- a/app/services/git_operation_service.rb +++ b/app/services/git_operation_service.rb @@ -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) |