1

I have a test project set up locally at;

~/development/test/

I have git initialised on it and I can push to my remote "test" repo fine. No issues with that.

I can run my post-update hook manually from the command line;

./post-update

It will launch a web browser because the file has the following contents;

#!/bin/bash
echo "Hook is running........."
python -mwebbrowser http://example.com

But when I do a git push -u origin master the file just does not seem to run. None of what is in the bash script seems to happen.

I have the file permissions set up correctly as stated in this post

Any ideas on what else to try?

Community
  • 1
  • 1
mikelovelyuk
  • 4,042
  • 9
  • 49
  • 95

1 Answers1

1

I guess you are using the wrong hook. Git hook documentation says :

post-update is invoked by git-receive-pack on the remote repository, which happens when a git push is done on a local repository. It executes on the remote repository once after all the refs have been updated.

You would like a post-push hook which doesn't exist. Instead you could used pre-push hook.

pre-push is called by git push. If this hook exits with a non-zero status, git push will abort without pushing anything.

The web browser will be opened before the push to be performed but if you open it on a background task (with character &) and return 0 it should do what you are looking for.

Your script will became

#!/bin/bash
echo "Hook is running........."
python -mwebbrowser http://example.com &
exit 0
Flows
  • 3,675
  • 3
  • 28
  • 52
  • ah, that does the trick. although, I will need to read/understand the docs as I will want to share this hook with people but as of right now it's only on my local machine, right? – mikelovelyuk Sep 07 '16 at 12:42
  • Yes, it is difficult to share a hook. You can create a symbolic link to your hook in all developers `.git/hook` folder, or commit a folder `hook` with hooks and script to launch to install them. But AFAIK there is not a simple way to deploy a hook with git. – Flows Sep 07 '16 at 12:56