Search code examples
windowsgitmsysgit

msysgit error with hooks: "git error: cannot spawn .git/hooks/post-commit: No such file or directory"


I'm having trouble getting post-recieve and post-commit hooks to work correctly with msysgit (Windows 7 Pro/32 and Ultimate/64). For post-commit hook I get the above error if I commit from either git-bash or the console, but it works fine if I commit through git-gui. For a post-recieve hook, all three give the same error.

I'm thinking this is some sort of permission or path error, but don't really have any clue where to start here.


Solution

  • Add the SHEBANG to the first line of hook, like so:

    #!/bin/sh
    echo "executing post-commit"
    exit 0
    

    This had me stumped for a while as well and I saw that adding the shebang fixed it. In SVN world, while in *nix we have a "pre-commit" script and in Windows we had "pre-commit.bat" and SVN automatically picked up the bat file in Windows. Git doesn't seem to pick up a pre-commit.bat ( or any hook ) and adding the shebang to the hook file worked.