In this case, I think you will have to use the --commit-filter . This is the only way to simultaneously receive both a commit message (from stdin) and environment variables. The new script will have to fully reproduce all the functionality of commit-tree . Fortunately, it will not look the same as the GitHub script you linked.
First read the entire commit message in the Bash variable:
commitmsg=$(cat)
Now get the first line and check if it matches:
firstline=$(echo "$commitmsg" | head -n1 | grep "Adding new domains:") if [ "$firstline" ]; then
We matched the commit message, so we do a regular replacement, as in the GitHub script.
export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi
Now we have to call git commit-tree . A commit message is provided on stdin as we received it. Since our script acts as a surrogate for commit-tree , we also need to pass all the arguments. The environment variables that we (possibly modified) take care of themselves.
echo "$commitmsg" | git commit-tree " $@ "
This produces a hash on stdout, as we should do. This is where we are done!
Here is a copy of the completed script. YMMV, of course, but I tested it and it works great.
source share