summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-09-08 10:51:50 +0000
committerDouwe Maan <douwe@gitlab.com>2016-09-08 10:51:50 +0000
commit55cc8777a995d366ff5114beb235f16093bf57df (patch)
treeecc8efcf226f98ee60a5a5bafe12d47548dcbbe6 /app
parent7f07b1b6f0aaa52adc1e3ed052d71f712b1a6be2 (diff)
parent084bac8935f6532d28db71fbf14e68d9060337e8 (diff)
downloadgitlab-ce-55cc8777a995d366ff5114beb235f16093bf57df.tar.gz
Merge branch 'ref-update-multiple-commits' into 'master'
Allow updating a branch by multiple commits In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6130 we made Repository#commit_with_hooks a bit too strict; it only allowed updating a branch by one commit. It turns out there is a feature in GitLab Enterprise Edition where we update by multiple commits. This change makes that possible, adds tests, and renames the method to the more appropriate 'update_branch_with_hooks'. See merge request !6246
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb24
1 files changed, 14 insertions, 10 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 414b82516bc..7b7090b8a73 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -757,7 +757,7 @@ class Repository
end
def commit_dir(user, path, message, branch)
- commit_with_hooks(user, branch) do |ref|
+ update_branch_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)
options = {}
options[:committer] = committer
@@ -774,7 +774,7 @@ class Repository
end
def commit_file(user, path, content, message, branch, update)
- commit_with_hooks(user, branch) do |ref|
+ update_branch_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)
options = {}
options[:committer] = committer
@@ -796,7 +796,7 @@ class Repository
end
def update_file(user, path, content, branch:, previous_path:, message:)
- commit_with_hooks(user, branch) do |ref|
+ update_branch_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)
options = {}
options[:committer] = committer
@@ -823,7 +823,7 @@ class Repository
end
def remove_file(user, path, message, branch)
- commit_with_hooks(user, branch) do |ref|
+ update_branch_with_hooks(user, branch) do |ref|
committer = user_to_committer(user)
options = {}
options[:committer] = committer
@@ -871,7 +871,7 @@ class Repository
merge_index = rugged.merge_commits(our_commit, their_commit)
return false if merge_index.conflicts?
- commit_with_hooks(user, merge_request.target_branch) do
+ update_branch_with_hooks(user, merge_request.target_branch) do
actual_options = options.merge(
parents: [our_commit, their_commit],
tree: merge_index.write_tree(rugged),
@@ -889,7 +889,7 @@ class Repository
return false unless revert_tree_id
- commit_with_hooks(user, base_branch) do
+ update_branch_with_hooks(user, base_branch) do
committer = user_to_committer(user)
source_sha = Rugged::Commit.create(rugged,
message: commit.revert_message,
@@ -906,7 +906,7 @@ class Repository
return false unless cherry_pick_tree_id
- commit_with_hooks(user, base_branch) do
+ update_branch_with_hooks(user, base_branch) do
committer = user_to_committer(user)
source_sha = Rugged::Commit.create(rugged,
message: commit.message,
@@ -922,7 +922,7 @@ class Repository
end
def resolve_conflicts(user, branch, params)
- commit_with_hooks(user, branch) do
+ update_branch_with_hooks(user, branch) do
committer = user_to_committer(user)
Rugged::Commit.create(rugged, params.merge(author: committer, committer: committer))
@@ -1026,7 +1026,7 @@ class Repository
Gitlab::Popen.popen(args, path_to_repo)
end
- def commit_with_hooks(current_user, branch)
+ def update_branch_with_hooks(current_user, branch)
update_autocrlf_option
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch
@@ -1040,7 +1040,11 @@ class Repository
raise CommitError.new('Failed to create commit')
end
- oldrev = rugged.lookup(newrev).parent_ids.first || Gitlab::Git::BLANK_SHA
+ if rugged.lookup(newrev).parent_ids.empty? || target_branch.nil?
+ oldrev = Gitlab::Git::BLANK_SHA
+ else
+ oldrev = rugged.merge_base(newrev, target_branch.target.sha)
+ end
GitHooksService.new.execute(current_user, path_to_repo, oldrev, newrev, ref) do
update_ref!(ref, newrev, oldrev)