Skip to content

Web UI create/delete branch actions do not trigger custom hooks

(Copied from https://github.com/gitlabhq/gitlabhq/issues/8428)

Summary

When creating or deleting a branch from GitLab web UI, the custom hooks in repository custom_hooks directory are not called.

Otherwise the custom hooks work as expected.

Detailed description

(Copied from GitHub)

This doesn't have anything to do with the custom hooks itself, but with the trigger that invokes them when using GitLab web UI.

Let me describe the scenario. I have a repo in GitLab and a custom hook that synchronizes to a remote Puppet repo.

The following is working seamlessly when working from a local clone of the repo and pushing to GitLab:

  1. Create a new branch and push it → custom hooks are called and branch is synced in Puppet repo.
  2. Delete a remote branch (e.g. git push origin :branchname) → custom hooks are called and branch is deleted in Puppet repo.

However, if I do the same operations through GitLab web UI, the custom hooks are not called:

  1. Create a new branch → branch is created in GitLab, but the custom hooks are not called.
  2. Delete the branch → branch is deleted in GitLab, but the custom hooks are not called.

It seems that the code that needs to trigger the hooks events is not being called. Part of that code does seem to exist because the custom hooks are called when I do edit and merge operations through the web UI.

Steps to reproduce

  1. Create test/test-hooks project in GitLab.

  2. Setup a custom post-receive hook that logs calls in the test-hooks project:

     sudo su git
     POSTRECEIVE_HOOK="/var/opt/gitlab/git-data/repositories/test/test-hooks.git/custom_hooks/post-receive"
     mkdir `dirname "$POSTRECEIVE_HOOK"`
     cat > "$POSTRECEIVE_HOOK" <<'EOT'
     #!/bin/bash
     while read oldrev newrev refname
     do
         echo "`date`: hook triggered with $oldrev $newrev $refname" >> "/tmp/post-receive.log"
     done
     EOT
     chmod 755 "$POSTRECEIVE_HOOK"
  3. Test that the script works manually:

     echo a b master | "$POSTRECEIVE_HOOK"
     cat /tmp/post-receive.log
     # should display <<date>>: hook triggered with a b master
  4. Test that the script is called when you create a branch from command line:

     cd /tmp
     git clone localhost:test/test-hooks.git
     cd test-hooks
     git checkout -b test
     git push origin test
     cat /tmp/post-receive.log
     # should display <<date>>: hook triggered with 00...00 xyz refs/heads/test
  5. Delete the test branch in GitLab web UI.

  6. Create a new branch test2 in GitLab web UI.

Expected behavior

For step (5) above, expected to see the following line in /tmp/post-receive.log:

<<date>>: hook triggered with xyz 00...00 refs/heads/test

For step (6) above, expected to see the following line in /tmp/post-receive.log:

<<date>>: hook triggered with 00...00 xyz refs/heads/test2

Observed behavior

Expected lines do not appear in log.