Commit 28b462c7 authored by Sean McGivern's avatar Sean McGivern

Change Repository#merge interface for squashing

When squashing, we may want to merge a different commit than the MR's
HEAD commit into the target branch. This interface matches the existing
`Repository#ff_merge` method, and allows us to pick an arbitrary commit
to merge.
parent 59577507
......@@ -1027,9 +1027,9 @@ class Repository
end
end
def merge(user, merge_request, options = {})
our_commit = rugged.branches[merge_request.target_branch].target
their_commit = rugged.lookup(merge_request.diff_head_sha)
def merge(user, source, target_branch, merge_request, options = {})
our_commit = rugged.branches[target_branch].target
their_commit = rugged.lookup(source)
raise "Invalid merge target" if our_commit.nil?
raise "Invalid merge source" if their_commit.nil?
......@@ -1037,7 +1037,7 @@ class Repository
merge_index = rugged.merge_commits(our_commit, their_commit)
return false if merge_index.conflicts?
update_branch_with_hooks(user, merge_request.target_branch) do
update_branch_with_hooks(user, target_branch) do
actual_options = options.merge(
parents: [our_commit, their_commit],
tree: merge_index.write_tree(rugged),
......
......@@ -64,7 +64,11 @@ module MergeRequests
committer: committer
}
commit_id = repository.merge(current_user, merge_request, options)
commit_id = repository.merge(current_user,
merge_request.diff_head_sha,
merge_request.target_branch,
merge_request,
options)
if commit_id
merge_request.update(merge_commit_sha: commit_id)
......
......@@ -1640,7 +1640,13 @@ describe Gitlab::Diff::PositionTracer, lib: true do
}
merge_request = create(:merge_request, source_branch: second_create_file_commit.sha, target_branch: branch_name, source_project: project)
repository.merge(current_user, merge_request, options)
repository.merge(current_user,
merge_request.diff_head_sha,
merge_request.target_branch,
merge_request,
options)
project.commit(branch_name)
end
......
......@@ -15,7 +15,13 @@ describe Repository, models: true do
let(:merge_commit) do
merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'master', source_project: project)
merge_commit_id = repository.merge(user, merge_request, commit_options)
merge_commit_id = repository.merge(user,
merge_request.diff_head_sha,
merge_request.target_branch,
merge_request,
commit_options)
repository.commit(merge_commit_id)
end
......@@ -1009,8 +1015,12 @@ describe Repository, models: true do
it 'sets the `in_progress_merge_commit_sha` flag for the given merge request' do
merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'master', source_project: project)
merge_commit_id = repository.merge(user, merge_request, commit_options)
repository.commit(merge_commit_id)
merge_commit_id = repository.merge(user,
merge_request.diff_head_sha,
merge_request.target_branch,
merge_request,
commit_options)
expect(merge_request.in_progress_merge_commit_sha).to eq(merge_commit_id)
end
......
......@@ -101,7 +101,13 @@ describe MergeRequests::RefreshService, services: true do
# Merge master -> feature branch
author = { email: 'test@gitlab.com', time: Time.now, name: "Me" }
commit_options = { message: 'Test message', committer: author, author: author }
@project.repository.merge(@user, @merge_request, commit_options)
@project.repository.merge(@user,
@merge_request.diff_head_sha,
@merge_request.target_branch,
@merge_request,
commit_options)
commit = @project.repository.commit('feature')
service.new(@project, @user).execute(@oldrev, commit.id, 'refs/heads/feature')
reload_mrs
......
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