Pre-commit hooks don't execute

1,120 views
Skip to first unread message

ymek...@gmail.com

unread,
Mar 12, 2014, 11:05:52 AM3/12/14
to tortoise...@googlegroups.com
Hi!

I would like to add some additional validation and functionality to my commits. For that, I created a very simple python script which I saved as 'pre-commit' in the ./git/hooks folder.
This works as expected when commiting from the command line, but not when committing with TortoiseGit.

Do I have to do any additional configuration to enable pre-commit hook scripts? The 'Hook Scripts' Settings only allow for Pre-/Post-Push Hooks, which are of no use for me.
I'm working on Win 7, if that's of any matter.

ch3c...@gmail.com

unread,
Mar 12, 2014, 11:39:22 AM3/12/14
to tortoise...@googlegroups.com, ymek...@gmail.com
It works for me in ToroiseGit too.
Do you have python in $PATH environment variable?
What is the shebang in pre-commit?

ymek...@gmail.com於 2014年3月12日星期三UTC+8下午11時05分52秒寫道:

Yue Lin Ho

unread,
Mar 12, 2014, 12:48:12 PM3/12/14
to tortoise...@googlegroups.com, ymek...@gmail.com
Hi:

ch3c...@gmail.com於 2014年3月12日星期三UTC+8下午11時39分22秒寫道:
works for me, too.

----

My testing:

There is a file named "pre-commit.sample" in .git/hooks folder, I rename it to "pre-commit".

Then, commit the file named "新文字文件.txt" and the error:

Error: Attempt to add a non-ASCII file name.

This can cause problems if you want to work with people on other platforms.

To be portable it is advisable to rename the file.

If you know what you are doing you can disable this check using:

  git config hooks.allownonascii true


git did not exit cleanly (exit code 1) (3370 ms @ 2014-03-13 00:28:02)


Does the firewall block it? 
(The first time I use "pre-commit", my firewall block it and it commit Success)

ymek...@gmail.com

unread,
Mar 13, 2014, 4:13:17 AM3/13/14
to tortoise...@googlegroups.com, ymek...@gmail.com
I realized the error was on my part, as I did not fully realize how TortoiseGit works. I expected the hook to trigger when you load up the TortoiseGit Commit window. I tested it again today on a test repository (I couldn't randomly commit to test stuff on the system I worked at yesterday) and saw just now that it triggers the hook after clicking 'commit', as it doesn't call a git command before that.

So it works for now (but only after I updated to python 3.3, there seems to be a bug with python 3.2 preventing it to work when called from Tortoise.), thank you for checking!
Reply all
Reply to author
Forward
0 new messages