Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post Commit Hook Not Running

My post commit hook is not running after git. I have verified that the hook does work if I just run it from the terminal. The code in the hook is:

#!/bin/sh #.git/hooks/post-commit # An example hook script that is called after a successful # commit is made. # # To enable this hook, rename this file to "post-commit".  perl -pi -e 's/([a-f0-9]+)$/'$( git rev-parse HEAD )/ ../../config/commit.git 

I did rename the file to post-commit in ./.git/hooks/ and the permissions are -rwxr-x-r-x so I am not sure why it doesn't work.

like image 414
Dave Long Avatar asked Feb 22 '11 21:02

Dave Long


People also ask

What is post-commit hook in git?

The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.

How do you force a pre-commit hook?

pre-commit will now run on every commit. Every time you clone a project using pre-commit running pre-commit install should always be the first thing you do. If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> .


2 Answers

I'll leave this here as an answer because I stumbled upon my own answer for when my post-commit hook wasn't running:

chmod +x .git/hooks/post-commit

Probably applies to any kind of hook. In fact, probably applies to any kind of script.

like image 57
Steven Lu Avatar answered Sep 25 '22 05:09

Steven Lu


Try putting some echo lines before and after the perl line like this:

echo "post-commit started" perl ........... echo "post-commit finished" 

This way you can confirm if the script is actually running, because when you run

git commit 

you should see

post-commit started post-commit finished 

Towards the end of your output.

like image 22
Peter Farmer Avatar answered Sep 25 '22 05:09

Peter Farmer