mikelovelyuk
mikelovelyuk

Reputation: 4152

Git Hook Post Update File Not Running

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?

Upvotes: 1

Views: 1916

Answers (1)

Flows
Flows

Reputation: 3863

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

Upvotes: 2

Related Questions