Commit 1ca6e99d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'squash' into 'master'

Backport changes from EE squash

See merge request !8912
parents 7dc8b6b2 7550f60d
...@@ -56,15 +56,24 @@ ...@@ -56,15 +56,24 @@
&.right { &.right {
float: right; float: right;
padding-right: 0; padding-right: 0;
}
a { .modify-merge-commit-link {
color: $gl-text-color; color: $gl-text-color;
}
} }
.remove_source_checkbox { .merge-param-checkbox {
margin: 0; margin: 0;
} }
a .fa-question-circle {
color: $gl-text-color-secondary;
&:hover,
&:focus {
color: $link-hover-color;
}
}
} }
} }
......
...@@ -143,4 +143,16 @@ module MergeRequestsHelper ...@@ -143,4 +143,16 @@ module MergeRequestsHelper
def different_base?(version1, version2) def different_base?(version1, version2)
version1 && version2 && version1.base_commit_sha != version2.base_commit_sha version1 && version2 && version1.base_commit_sha != version2.base_commit_sha
end end
def merge_params(merge_request)
{
merge_when_build_succeeds: true,
should_remove_source_branch: true,
sha: merge_request.diff_head_sha
}.merge(merge_params_ee(merge_request))
end
def merge_params_ee(merge_request)
{}
end
end end
...@@ -913,11 +913,11 @@ class Repository ...@@ -913,11 +913,11 @@ class Repository
end end
end end
def merge(user, merge_request, options = {}) def merge(user, source, merge_request, options = {})
GitOperationService.new(user, self).with_branch( GitOperationService.new(user, self).with_branch(
merge_request.target_branch) do |start_commit| merge_request.target_branch) do |start_commit|
our_commit = start_commit.sha our_commit = start_commit.sha
their_commit = merge_request.diff_head_sha their_commit = source
raise 'Invalid merge target' unless our_commit raise 'Invalid merge target' unless our_commit
raise 'Invalid merge source' unless their_commit raise 'Invalid merge source' unless their_commit
......
...@@ -6,13 +6,17 @@ module MergeRequests ...@@ -6,13 +6,17 @@ module MergeRequests
# Executed when you do merge via GitLab UI # Executed when you do merge via GitLab UI
# #
class MergeService < MergeRequests::BaseService class MergeService < MergeRequests::BaseService
attr_reader :merge_request attr_reader :merge_request, :source
def execute(merge_request) def execute(merge_request)
@merge_request = merge_request @merge_request = merge_request
return log_merge_error('Merge request is not mergeable', true) unless @merge_request.mergeable? return log_merge_error('Merge request is not mergeable', true) unless @merge_request.mergeable?
@source = find_merge_source
return log_merge_error('No source for merge', true) unless @source
merge_request.in_locked_state do merge_request.in_locked_state do
if commit if commit
after_merge after_merge
...@@ -34,7 +38,7 @@ module MergeRequests ...@@ -34,7 +38,7 @@ module MergeRequests
committer: committer committer: committer
} }
commit_id = repository.merge(current_user, merge_request, options) commit_id = repository.merge(current_user, source, merge_request, options)
if commit_id if commit_id
merge_request.update(merge_commit_sha: commit_id) merge_request.update(merge_commit_sha: commit_id)
...@@ -73,9 +77,11 @@ module MergeRequests ...@@ -73,9 +77,11 @@ module MergeRequests
end end
def merge_request_info def merge_request_info
project = merge_request.project merge_request.to_reference(full: true)
end
"#{project.to_reference}#{merge_request.to_reference}" def find_merge_source
merge_request.diff_head_sha
end end
end end
end end
...@@ -35,10 +35,10 @@ ...@@ -35,10 +35,10 @@
The source branch will be removed. The source branch will be removed.
- elsif @merge_request.can_remove_source_branch?(current_user) - elsif @merge_request.can_remove_source_branch?(current_user)
.accept-control.checkbox .accept-control.checkbox
= label_tag :should_remove_source_branch, class: "remove_source_checkbox" do = label_tag :should_remove_source_branch, class: "merge-param-checkbox" do
= check_box_tag :should_remove_source_branch = check_box_tag :should_remove_source_branch
Remove source branch Remove source branch
.accept-control.right .accept-control
= link_to "#", class: "modify-merge-commit-link js-toggle-button" do = link_to "#", class: "modify-merge-commit-link js-toggle-button" do
= icon('edit') = icon('edit')
Modify commit message Modify commit message
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
- if remove_source_branch_button || user_can_cancel_automatic_merge - if remove_source_branch_button || user_can_cancel_automatic_merge
.clearfix.prepend-top-10 .clearfix.prepend-top-10
- if remove_source_branch_button - if remove_source_branch_button
= link_to merge_namespace_project_merge_request_path(@merge_request.target_project.namespace, @merge_request.target_project, @merge_request, merge_when_build_succeeds: true, should_remove_source_branch: true, sha: @merge_request.diff_head_sha), remote: true, method: :post, class: "btn btn-grouped btn-primary btn-sm remove_source_branch" do = link_to merge_namespace_project_merge_request_path(@merge_request.target_project.namespace, @merge_request.target_project, @merge_request, merge_params(@merge_request)), remote: true, method: :post, class: "btn btn-grouped btn-primary btn-sm remove_source_branch" do
= icon('times') = icon('times')
Remove Source Branch When Merged Remove Source Branch When Merged
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
= render 'shared/issuable/form/branch_chooser', issuable: issuable, form: form = render 'shared/issuable/form/branch_chooser', issuable: issuable, form: form
= render 'shared/issuable/form/merge_params', issuable: issuable
- if @merge_request_for_resolving_discussions - if @merge_request_for_resolving_discussions
.form-group .form-group
.col-sm-10.col-sm-offset-2 .col-sm-10.col-sm-offset-2
......
...@@ -19,12 +19,3 @@ ...@@ -19,12 +19,3 @@
- if issuable.new_record? - if issuable.new_record?
&nbsp; &nbsp;
= link_to 'Change branches', mr_change_branches_path(issuable) = link_to 'Change branches', mr_change_branches_path(issuable)
- if issuable.can_remove_source_branch?(current_user)
.form-group
.col-sm-10.col-sm-offset-2
.checkbox
= label_tag 'merge_request[force_remove_source_branch]' do
= hidden_field_tag 'merge_request[force_remove_source_branch]', '0', id: nil
= check_box_tag 'merge_request[force_remove_source_branch]', '1', issuable.force_remove_source_branch?
Remove source branch when merge request is accepted.
- issuable = local_assigns.fetch(:issuable)
- return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_without_fork?
-# This check is duplicated below, to avoid conflicts with EE.
- return unless issuable.can_remove_source_branch?(current_user)
.form-group
.col-sm-10.col-sm-offset-2
- if issuable.can_remove_source_branch?(current_user)
.checkbox
= label_tag 'merge_request[force_remove_source_branch]' do
= hidden_field_tag 'merge_request[force_remove_source_branch]', '0', id: nil
= check_box_tag 'merge_request[force_remove_source_branch]', '1', issuable.force_remove_source_branch?
Remove source branch when merge request is accepted.
...@@ -1640,7 +1640,9 @@ describe Gitlab::Diff::PositionTracer, lib: true do ...@@ -1640,7 +1640,9 @@ 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) 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, options)
project.commit(branch_name) project.commit(branch_name)
end end
......
...@@ -15,7 +15,12 @@ describe Repository, models: true do ...@@ -15,7 +15,12 @@ describe Repository, models: true do
let(:merge_commit) do let(:merge_commit) do
merge_request = create(:merge_request, source_branch: 'feature', target_branch: 'master', source_project: project) 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,
commit_options)
repository.commit(merge_commit_id) repository.commit(merge_commit_id)
end end
...@@ -1082,8 +1087,11 @@ describe Repository, models: true do ...@@ -1082,8 +1087,11 @@ describe Repository, models: true do
it 'sets the `in_progress_merge_commit_sha` flag for the given merge request' 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_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,
commit_options)
expect(merge_request.in_progress_merge_commit_sha).to eq(merge_commit_id) expect(merge_request.in_progress_merge_commit_sha).to eq(merge_commit_id)
end end
......
...@@ -89,7 +89,7 @@ describe MergeRequests::RefreshService, services: true do ...@@ -89,7 +89,7 @@ describe MergeRequests::RefreshService, services: true do
# Merge master -> feature branch # Merge master -> feature branch
author = { email: 'test@gitlab.com', time: Time.now, name: "Me" } author = { email: 'test@gitlab.com', time: Time.now, name: "Me" }
commit_options = { message: 'Test message', committer: author, author: author } 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, commit_options)
commit = @project.repository.commit('feature') commit = @project.repository.commit('feature')
service.new(@project, @user).execute(@oldrev, commit.id, 'refs/heads/feature') service.new(@project, @user).execute(@oldrev, commit.id, 'refs/heads/feature')
reload_mrs reload_mrs
......
...@@ -36,7 +36,8 @@ module TestEnv ...@@ -36,7 +36,8 @@ module TestEnv
'conflict-non-utf8' => 'd0a293c', 'conflict-non-utf8' => 'd0a293c',
'conflict-too-large' => '39fa04f', 'conflict-too-large' => '39fa04f',
'deleted-image-test' => '6c17798', 'deleted-image-test' => '6c17798',
'wip' => 'b9238ee' 'wip' => 'b9238ee',
'csv' => '3dd0896'
} }
# gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
......
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