So if .git/hooks/pre-commit exists, then it will be run right after:
git commit -am "foobar"
is run. So then how do I access the desired git commit message in the pre-commit?
I do some sleuthing and put this in .git/hooks/pre-commit and made the file executable:
#!/usr/bin/env bash
echo "here is pre-commit hook"
env | sort
echo "args:"
echo $@
exit 1;
here are the env vars that are prefixed with "GIT"
GIT_AUTHOR_DATE=@1558245421 -0700
GIT_AUTHOR_EMAIL=alex@alexs-mac.local
GIT_AUTHOR_NAME=Alexander Mills
GIT_EDITOR=:
GIT_EXEC_PATH=/Library/Developer/CommandLineTools/usr/libexec/git-core
GIT_INDEX_FILE=/Users/alex/codes/interos/notifier-server/.git/index.lock
GIT_PREFIX=
and there seem to be no arguments to the script, because nothing gets logged after echo "args:"
...
so how do I access the desired commit message in a pre-commit hook?
Specifically I am looking to bail from pre-commit if the commit-message does not have a good format. If there is another hook that can do that, then that would be a good answer to this question.