summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-05-02 16:02:43 +0000
committerNick Thomas <nick@gitlab.com>2018-05-02 16:02:43 +0000
commit59f79383a7f8dadd9c356f3872133e7675dd61c5 (patch)
treebe37a7cf50e2963ab25721360ad27471370c1868 /app/services
parentdbe12754be46786f4ac71d2e45e39f525c74f0cb (diff)
parentd973872072097152bf16ebb808a2c65912b9f3d0 (diff)
downloadgitlab-ce-59f79383a7f8dadd9c356f3872133e7675dd61c5.tar.gz
Merge branch 'jprovazn-generic-error' into 'master'
Save and expose only generic merge error See merge request gitlab-org/gitlab-ce!18646
Diffstat (limited to 'app/services')
-rw-r--r--app/services/merge_requests/merge_service.rb29
1 files changed, 19 insertions, 10 deletions
diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb
index cedfcb50e09..2209a60a840 100644
--- a/app/services/merge_requests/merge_service.rb
+++ b/app/services/merge_requests/merge_service.rb
@@ -50,21 +50,30 @@ module MergeRequests
end
def commit
- message = params[:commit_message] || merge_request.merge_commit_message
-
log_info("Git merge started on JID #{merge_jid}")
- commit_id = repository.merge(current_user, source, merge_request, message)
- log_info("Git merge finished on JID #{merge_jid} commit #{commit_id}")
+ commit_id = try_merge
+
+ if commit_id
+ log_info("Git merge finished on JID #{merge_jid} commit #{commit_id}")
+ else
+ raise MergeError, 'Conflicts detected during merge'
+ end
- raise MergeError, 'Conflicts detected during merge' unless commit_id
+ merge_request.update!(merge_commit_sha: commit_id)
+ end
+
+ def try_merge
+ message = params[:commit_message] || merge_request.merge_commit_message
- merge_request.update(merge_commit_sha: commit_id)
+ repository.merge(current_user, source, merge_request, message)
rescue Gitlab::Git::HooksService::PreReceiveError => e
- raise MergeError, e.message
- rescue StandardError => e
- raise MergeError, "Something went wrong during merge: #{e.message}"
+ handle_merge_error(log_message: e.message)
+ raise MergeError, 'Something went wrong during merge pre-receive hook'
+ rescue => e
+ handle_merge_error(log_message: e.message)
+ raise MergeError, 'Something went wrong during merge'
ensure
- merge_request.update(in_progress_merge_commit_sha: nil)
+ merge_request.update!(in_progress_merge_commit_sha: nil)
end
def after_merge