diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-11-09 14:55:45 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-11-10 12:01:09 -0200 |
commit | bddbb90fd985df50d4b17d0728ef5fa90bf64af7 (patch) | |
tree | 066c1bf6adca984b1a47800d7a5ad78d617ca2ac /app | |
parent | 65faebb95556809c5858347f1c24422505056827 (diff) | |
download | gitlab-ce-bddbb90fd985df50d4b17d0728ef5fa90bf64af7.tar.gz |
Prevent fast forward merge when rebase is requiredissue_39773_be
Diffstat (limited to 'app')
-rw-r--r-- | app/services/merge_requests/merge_service.rb | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb index 156e7b2f078..1da4dbd9e96 100644 --- a/app/services/merge_requests/merge_service.rb +++ b/app/services/merge_requests/merge_service.rb @@ -18,15 +18,7 @@ module MergeRequests @merge_request = merge_request - unless @merge_request.mergeable? - return handle_merge_error(log_message: 'Merge request is not mergeable', save_message_on_model: true) - end - - @source = find_merge_source - - unless @source - return handle_merge_error(log_message: 'No source for merge', save_message_on_model: true) - end + error_check! merge_request.in_locked_state do if commit @@ -41,6 +33,19 @@ module MergeRequests private + def error_check! + error = + if @merge_request.should_be_rebased? + 'Only fast-forward merge is allowed for your project. Please update your source branch' + elsif !@merge_request.mergeable? + 'Merge request is not mergeable' + elsif !source + 'No source for merge' + end + + raise MergeError, error if error + end + def commit message = params[:commit_message] || merge_request.merge_commit_message @@ -91,8 +96,8 @@ module MergeRequests merge_request.to_reference(full: true) end - def find_merge_source - merge_request.diff_head_sha + def source + @source ||= @merge_request.diff_head_sha end end end |