Commit 59577507 authored by Sean McGivern's avatar Sean McGivern

Add squash option to MR UI

parent ce33c294
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
} }
} }
.remove_source_checkbox { .merge-param-checkbox {
margin: 0; margin: 0;
} }
} }
......
...@@ -338,7 +338,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -338,7 +338,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return return
end end
@merge_request.update(merge_error: nil) @merge_request.update(merge_error: nil, squash: merge_params[:squash])
if params[:merge_when_build_succeeds].present? if params[:merge_when_build_succeeds].present?
unless @merge_request.head_pipeline unless @merge_request.head_pipeline
...@@ -699,6 +699,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -699,6 +699,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
approvals_before_merge approvals_before_merge
approver_group_ids approver_group_ids
approver_ids approver_ids
squash
] ]
end end
...@@ -716,7 +717,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -716,7 +717,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def merge_params def merge_params
params.permit(:should_remove_source_branch, :commit_message) params.permit(:should_remove_source_branch, :commit_message, :squash)
end end
# Make sure merge requests created before 8.0 # Make sure merge requests created before 8.0
......
...@@ -35,9 +35,14 @@ ...@@ -35,9 +35,14 @@
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.checkbox
= label_tag :squash, class: 'merge-param-checkbox' do
= hidden_field_tag :squash, '0', id: nil
= check_box_tag :squash, '1', @merge_request.squash
Squash commits
.accept-control.right .accept-control.right
- if @project.merge_requests_ff_only_enabled - if @project.merge_requests_ff_only_enabled
......
...@@ -7,10 +7,12 @@ ...@@ -7,10 +7,12 @@
%div %div
%p %p
= succeed '.' do = succeed '.' do
The changes will be
- if @merge_request.squash
squashed and
- if @project.merge_requests_ff_only_enabled - if @project.merge_requests_ff_only_enabled
The changes will be fast-forward merged into fast-forward
- else merged into
The changes will be merged into
%span.label-branch= @merge_request.target_branch %span.label-branch= @merge_request.target_branch
- if @merge_request.remove_source_branch? - if @merge_request.remove_source_branch?
The source branch will be removed. The source branch will be removed.
......
...@@ -28,3 +28,12 @@ ...@@ -28,3 +28,12 @@
= hidden_field_tag 'merge_request[force_remove_source_branch]', '0', id: nil = 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? = check_box_tag 'merge_request[force_remove_source_branch]', '1', issuable.force_remove_source_branch?
Remove source branch when merge request is accepted. Remove source branch when merge request is accepted.
- if issuable.new_record?
.form-group
.col-sm-10.col-sm-offset-2
.checkbox
= label_tag 'merge_request[squash]' do
= check_box_tag 'merge_request[squash]', nil
Squash commits on merge. The commit message for the last commit will
be used.
class AddSquashToMergeRequests < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_column_with_default :merge_requests, :squash, :boolean, default: false, allow_null: false
end
def down
remove_column :merge_requests, :squash
end
end
...@@ -782,6 +782,7 @@ ActiveRecord::Schema.define(version: 20170121130655) do ...@@ -782,6 +782,7 @@ ActiveRecord::Schema.define(version: 20170121130655) do
t.text "title_html" t.text "title_html"
t.text "description_html" t.text "description_html"
t.integer "time_estimate" t.integer "time_estimate"
t.boolean "squash", default: false, null: false
end end
add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
......
...@@ -492,6 +492,7 @@ describe Projects::MergeRequestsController do ...@@ -492,6 +492,7 @@ describe Projects::MergeRequestsController do
namespace_id: project.namespace.path, namespace_id: project.namespace.path,
project_id: project.path, project_id: project.path,
id: merge_request.iid, id: merge_request.iid,
squash: false,
format: 'raw' format: 'raw'
} }
end end
...@@ -529,8 +530,26 @@ describe Projects::MergeRequestsController do ...@@ -529,8 +530,26 @@ describe Projects::MergeRequestsController do
end end
context 'when the sha parameter matches the source SHA' do context 'when the sha parameter matches the source SHA' do
def merge_with_sha def merge_with_sha(params = {})
post :merge, base_params.merge(sha: merge_request.diff_head_sha) post :merge, base_params.merge(sha: merge_request.diff_head_sha).merge(params)
end
context 'when squash is passed as 1' do
it 'updates the squash attribute on the MR to true' do
merge_request.update(squash: false)
merge_with_sha(squash: '1')
expect(merge_request.reload.squash).to be_truthy
end
end
context 'when squash is passed as 1' do
it 'updates the squash attribute on the MR to false' do
merge_request.update(squash: true)
merge_with_sha(squash: '0')
expect(merge_request.reload.squash).to be_falsey
end
end end
it 'returns :success' do it 'returns :success' do
......
...@@ -154,6 +154,7 @@ MergeRequest: ...@@ -154,6 +154,7 @@ MergeRequest:
- approvals_before_merge - approvals_before_merge
- rebase_commit_sha - rebase_commit_sha
- time_estimate - time_estimate
- squash
MergeRequestDiff: MergeRequestDiff:
- id - id
- state - state
......
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