diff options
author | Christian Couder <chriscool@tuxfamily.org> | 2019-07-14 20:19:13 +0200 |
---|---|---|
committer | Christian Couder <chriscool@tuxfamily.org> | 2019-07-17 13:32:41 +0200 |
commit | 8256d4075db4ee2d00897f21d34b78f092571f2c (patch) | |
tree | 0b409629901c06dd4e96f7cbf960d8fb0c1a1500 /spec/services | |
parent | 4f95a8d7f6612e8df138bd831db7f689a01ef9ca (diff) | |
download | gitlab-ce-8256d4075db4ee2d00897f21d34b78f092571f2c.tar.gz |
Support rm src branch on merge w/ push option
MergeRequests::PushOptionsHandlerService has been updated to allow
creating and updating merge requests with the
`remove_source_branch` set using git push options.
To create a new merge request and set it to remove the source branch
when it is merged:
git push -u origin -o merge_request.create \
-o merge_request.remove_source_branch
To update an existing merge request and set it to remove the source
branch when it is merged:
git push -u origin -o merge_request.remove_source_branch
Issue https://gitlab.com/gitlab-org/gitlab-ce/issues/64320
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/merge_requests/push_options_handler_service_spec.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb index 54b9c6dae38..ac40cf02c48 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -90,6 +90,16 @@ describe MergeRequests::PushOptionsHandlerService do end end + shared_examples_for 'a service that can remove the source branch when it is merged' do + subject(:last_mr) { MergeRequest.last } + + it 'returns true to force_remove_source_branch?' do + service.execute + + expect(last_mr.force_remove_source_branch?).to eq(true) + end + end + shared_examples_for 'a service that does not create a merge request' do it do expect { service.execute }.not_to change { MergeRequest.count } @@ -208,6 +218,72 @@ describe MergeRequests::PushOptionsHandlerService do end end + describe '`remove_source_branch` push option' do + let(:push_options) { { remove_source_branch: true } } + + context 'with a new branch' do + let(:changes) { new_branch_changes } + + it_behaves_like 'a service that does not create a merge request' + + it 'adds an error to the service' do + error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}" + + service.execute + + expect(service.errors).to include(error) + end + + context 'when coupled with the `create` push option' do + let(:push_options) { { create: true, remove_source_branch: true } } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can remove the source branch when it is merged' + end + end + + context 'with an existing branch but no open MR' do + let(:changes) { existing_branch_changes } + + it_behaves_like 'a service that does not create a merge request' + + it 'adds an error to the service' do + error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}" + + service.execute + + expect(service.errors).to include(error) + end + + context 'when coupled with the `create` push option' do + let(:push_options) { { create: true, remove_source_branch: true } } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can remove the source branch when it is merged' + end + end + + context 'with an existing branch that has a merge request open' do + let(:changes) { existing_branch_changes } + let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)} + + it_behaves_like 'a service that does not create a merge request' + it_behaves_like 'a service that can remove the source branch when it is merged' + end + + context 'with a deleted branch' do + let(:changes) { deleted_branch_changes } + + it_behaves_like 'a service that does nothing' + end + + context 'with the project default branch' do + let(:changes) { default_branch_changes } + + it_behaves_like 'a service that does nothing' + end + end + describe '`target` push option' do let(:push_options) { { target: target_branch } } |