BigW Consortium Gitlab

Commit 926a8ab4 by Valery Sizov

Handle custom Git hook result in GitLab UI

parent f60b48bd
......@@ -33,6 +33,7 @@ v 8.10.0 (unreleased)
- Add basic system information like memory and disk usage to the admin panel
- Don't garbage collect commits that have related DB records like comments
- More descriptive message for git hooks and file locks
- Handle custom Git hook result in GitLab UI
v 8.9.5 (unreleased)
- Improve the request / withdraw access button. !4860
......
......@@ -36,10 +36,13 @@ module MergeRequests
commit_id = repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
merge_request.update(merge_commit_sha: commit_id)
rescue GitHooksService::PreReceiveError => e
merge_request.update(merge_error: e.message)
false
rescue StandardError => e
merge_request.update(merge_error: "Something went wrong during merge")
Rails.logger.error(e.message)
return false
false
end
def after_merge
......
......@@ -41,7 +41,7 @@ module Gitlab
chdir: repo_path
}
Open3.popen3(vars, path, options) do |stdin, _, stderr, wait_thr|
Open3.popen3(vars, path, options) do |stdin, stdout, stderr, wait_thr|
exit_status = true
stdin.sync = true
......@@ -60,7 +60,7 @@ module Gitlab
unless wait_thr.value == 0
exit_status = false
exit_message = stderr.gets
exit_message = retrieve_error_message(stderr, stdout)
end
end
......@@ -76,6 +76,11 @@ module Gitlab
[status, nil]
end
def retrieve_error_message(stderr, stdout)
err_message = stderr.gets
err_message.blank? ? stdout.gets : err_message
end
end
end
end
......@@ -65,6 +65,16 @@ describe MergeRequests::MergeService, services: true do
expect(merge_request.merge_error).to eq("Something went wrong during merge")
end
it 'saves error if there is an PreReceiveError exception' do
allow(service).to receive(:repository).and_raise(GitHooksService::PreReceiveError, "error")
allow(service).to receive(:execute_hooks)
service.execute(merge_request)
expect(merge_request.merge_error).to eq("error")
end
end
end
end
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