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?

2
  • Do you have error message after doing the git push ?
    – Flows
    Commented Sep 7, 2016 at 11:54
  • @Flows No errors at all. Commented Sep 7, 2016 at 12:02

1 Answer 1

2

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
2
  • 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? Commented Sep 7, 2016 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
    Commented Sep 7, 2016 at 12:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.