Skip to content

Handle custom Git hook result in GitLab UI

Overview

The GitLab merge request UI should handle the returned result from a custom Git hook when a MR merge is attempted.

Reproduce

  1. Configure a custom project Git hook

This will reject any push to master which has any non-linear history

oldrev="$2"
newrev="$3"

merge_commit=$(git rev-list -n 1 --merges $oldrev..$newrev)
if [ -n "$merge_commit" ]; then
    echo "Merge commit detected: $merge_commit";
    exit 1
fi
  1. Create a new merge request that will be rejected due to non-linear history (contains a merge from another branch)
  2. Accept this merge request via the GitLab UI

Actual

  • "Something went wrong during merge" is displayed when accepting the MR.

Expected

  • Output of why the merge failed. eg. "Failed due to pre-receive hook" include hook output?

cc// @stanhu


ZD: https://gitlab.zendesk.com/agent/tickets/28113