简体   繁体   中英

Git hook not running on windows

I'm just getting started with hooks and have met some trouble with simply running the script, as I commit with git. The script works completely as intended when ran from bash terminal with the

bash pre-commit

command. But it doesn't run at all when committing with git.

The file is located at C:/path/to/my/project/.git/hooks/pre-commit, and the content of the file is:

#!/bin/bash

cd ../
cd ../
echo "pre-commit start"
if py -m unittest discover 2>&1 | grep -q "FAILED"; then
  echo "Test(s) FAILED"
  exit 1
fi
echo "pre-commit end"

I have tried running the chmod command in terminal, as suggested in other posts, with no change at all.

chmod +x pre-commit

The issue was that even though the file was located at C:/path/to/my/project/.git/hooks/pre-commit, where I had tested it from, the file was running in the C:/path/to/my/project/ directory. Thus calling "cd ../" twice resulted in the script exiting the project directory, which must have created some sort of error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM