5

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

1 Answers1

1

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.