post-commit hook failed (exit code 255) error

user1076881 picture user1076881 · Feb 27, 2012 · Viewed 8k times · Source

Committing file gives Warning: post-commit hook failed (exit code 255) with no output. No email is sent out too. My hooks/post-commit file has the following content

#!/bin/sh

REPOS="$1"
REV="$2"

"$REPOS"/hooks/mailer.py commit "$REPOS" $REV "$REPOS"/mailer.conf

How could I manually run that file to troubleshoot the problem? my mailer.py file is located under hooks folder too and mailer.conf is located outside of hooks folder.

Answer

David W. picture David W. · Feb 27, 2012

How could I manually run that file to troubleshoot the problem? my mailer.py file is located under hooks folder too and mailer.conf is located outside of hooks folder.

That's simple: Simply run the command manually.

$ cd $REPOS   #Where ever that is...
$ REV=230     #Whatever the revision number is

$ hooks/mailer.py commit . $REV mailer.conf

You can copy the mailer.py into another file, and play around with it. Add a few print statements, run it in the debugger, etc. For example, you probably want to futz the actual mail part of your program not to really mail everything out to the developers until you're ready to debug the particular sending mechanism. Developers don't like their mailboxes bombarded with a bunch of post-commit hook tests.

$ cp hooks/mailer.py hooks/mailer2.py
$ cp mailer.conf mailer2.conf
$ hooks/mailer2.py commit . $REV mailer.conf

What I'd suggest is that you disable your post-commit hook (in Unix/Linux, take off the executable bit should be sufficient, or simply rename post-commit to post-commit.temp). then have the user commit their change.

Once the change is committed, you have the revision number of the commit that caused the problem. Now, you can use that revision number when you manually run your post-commit hook.


Helpful Hint

If you're making a pre-commit hook, allow the hook to take either a transaction number or a revision number:

# Transaction number in pre-commit script:

REPOS="$1"
TRX="$2"

"$REPOS/hooks/myscript" -t $TRX "$REPOS"

From the command line:

 cd $REPOS
 hooks/myscript -r $REVISION .

This way, you can debug your pre-commit hook with already committed revisions. This is much, much easier than trying to debug by committing the same change over and over again.