I'd like to write a git hook such that commit will fail if our .env
file is not encrypted. However, git status
always exits with code 0. How can I have this command exit with an error code when the the file is not committed.
# file encrypted
git-crypt status .env && echo "exit 0" || echo "exit 1"
# encrypted: .env
# exit 0
# file not encrypted
git-crypt status package.json && echo "exit 0" || echo "exit 1"
# not encrypted: package.json
# exit 0
I was able to do this using grep.
Also works on multiple files.