PreReceiveHook and PostReceiveHook are not invoked
Symptoms
When using the Atlassian SDK to run Stash 2.0.x on Mac or Linux, the onReceive() method on a PreReceiveHook
or PostReceiveHook
is not triggered when pushing to the default repository (PROJECT_1
/ rep_1
). Branch permissions (which are implemented as PreReceiveHook
s) will also not work for rep_1
.
Cause
The hook scripts in the rep_1
repository in the default stash-plugin-test-resources.zip
setup by AMPS doesn't have the executable permissions set. git-receive-pack
ignores non-executable scripts, so no hooks are invoked when you push to rep_1
.
Resolutions
(The quick way) Create a new repository
Any new repositories will have their hook scripts correctly initialised, so the easiest way to workaround this issue is simply to create a new repository for testing your plugin.
That's it! Hooks should now work correctly for the newly created repository.
(The slightly longer way) Manually set the script permissions
- From your plugin directory, navigate to
/target/stash/home/data/repositories/1/hooks
- Run
ls -l *
You should see the following output:
tpettersen@hoprocker ~/example-plugin/target/stash/home/data/repositories/1/hooks (BARE:master) $ ls -l -r * -rw-r--r-- 1 tpettersen staff 3611 20 Dec 00:35 update.sample -rw-r--r-- 1 tpettersen staff 1239 20 Dec 00:35 prepare-commit-msg.sample -rw-r--r-- 1 tpettersen staff 424 20 Dec 00:35 pre-receive -rw-r--r-- 1 tpettersen staff 4951 20 Dec 00:35 pre-rebase.sample -rw-r--r-- 1 tpettersen staff 1704 20 Dec 00:35 pre-commit.sample -rw-r--r-- 1 tpettersen staff 398 20 Dec 00:35 pre-applypatch.sample -rw-r--r-- 1 tpettersen staff 189 20 Dec 00:35 post-update.sample -rw-r--r-- 1 tpettersen staff 426 20 Dec 00:35 post-receive -rw-r--r-- 1 tpettersen staff 896 20 Dec 00:35 commit-msg.sample -rw-r--r-- 1 tpettersen staff 452 20 Dec 00:35 applypatch-msg.sample pre-receive.d: total 8 -rw-r--r-- 1 tpettersen staff 410 20 Dec 00:35 20_stash_callback post-receive.d: total 8 -rw-r--r-- 1 tpettersen staff 412 20 Dec 00:35 20_stash_callback
- Run
chmod -R a+x *
- Run
ls -l *
again You should see the following output (note the scripts are now executable):
tpettersen@hoprocker ~/example-plugin/target/stash/home/data/repositories/1/hooks (BARE:master) $ chmod -R a+x * tpettersen@hoprocker ~/example-plugin/target/stash/home/data/repositories/1/hooks (BARE:master) $ ls -l * -rwxr-xr-x 1 tpettersen staff 452 20 Dec 00:35 applypatch-msg.sample -rwxr-xr-x 1 tpettersen staff 896 20 Dec 00:35 commit-msg.sample -rwxr-xr-x 1 tpettersen staff 426 20 Dec 00:35 post-receive -rwxr-xr-x 1 tpettersen staff 189 20 Dec 00:35 post-update.sample -rwxr-xr-x 1 tpettersen staff 398 20 Dec 00:35 pre-applypatch.sample -rwxr-xr-x 1 tpettersen staff 1704 20 Dec 00:35 pre-commit.sample -rwxr-xr-x 1 tpettersen staff 4951 20 Dec 00:35 pre-rebase.sample -rwxr-xr-x 1 tpettersen staff 424 20 Dec 00:35 pre-receive -rwxr-xr-x 1 tpettersen staff 1239 20 Dec 00:35 prepare-commit-msg.sample -rwxr-xr-x 1 tpettersen staff 3611 20 Dec 00:35 update.sample post-receive.d: total 8 -rwxr-xr-x 1 tpettersen staff 412 20 Dec 00:35 20_stash_callback pre-receive.d: total 8 -rwxr-xr-x 1 tpettersen staff 410 20 Dec 00:35 20_stash_callback
- Your commit hooks will be triggered on the next push to
rep_1
.