githooks - git pre-commit hook not running when running git commit -a -


i have local pre-commit hook executes, , stops commit expected when run git commit

also, expected, can bypass hook when run git commit -n ...

however, running git commit -am "my message" or indeed, git commit -a seems bypass hook , allow commit processed.

any idea why may happening?

edit: hook below.

project_root=`git rev-parse --show-toplevel` changed=`git diff --stat -- $project_root/myproj/myfile.ext | wc -l` if [ $changed -gt 0 ];     echo "myfile.ext file has changed, sure want commit"     echo "use -n parameter process commit."     exit 1 fi 

so, user error..

the hook running in both instances, logic used detect change in file didn't work when -a command supplied.

checking against remote repo did trick.

changed=`git diff origin/master --stat -- $project_root/myproj/myfile.ext | wc -l`

edit: @torek, more appropriate way check change is:

changed=`git diff --cached --stat -- $project_root/myproj/myfile.ext | wc -l` 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -