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:
- Create a new branch and push it → custom hooks are called and branch is synced in Puppet repo.
- 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:
- Create a new branch → branch is created in GitLab, but the custom hooks are not called.
- 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
-
Create
test/test-hooks
project in GitLab. -
Setup a custom
post-receive
hook that logs calls in thetest-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"
-
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
-
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
-
Delete the
test
branch in GitLab web UI. -
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.