[bind10-dev] automated branch name in commit messages
jelte at isc.org
Fri Jan 28 09:48:39 UTC 2011
-----BEGIN PGP SIGNED MESSAGE-----
So we agreed to put branch names in the first line of commit messages, and i'd
like to propose a way to do it automatically
We can put the following scripts in .git/hooks in the repository, but like code,
I want to have it looked at before we put it in, perhaps there's something
important i have not thought of, and I certainly don't want to mess up the repo :)
If we make a script .git/hooks/prepare-commit-message as follows:
BRANCH=`git branch | grep '^\*' | cut -b3-`
echo -n "[$BRANCH]" > "$1.msg"
cat "$1" >> "$1.msg"
cat "$1.msg" > "$1"
It will put [<branchname>] in the first line of the commit message
it will also leave a .msg file in .git, which is used by the second script i'd
like to propose; .git/hooks/commit-msg:
if diff "$1" "$1.msg" > /dev/null; then
echo >&2 Aborting commit due to unchanged commit message.
Normally, git will abort the commit if you leave the message empty, which
without the previous script is if you exit your editor without saving, but since
the first script already changes it, you'd have to delete the line added by that
one. This second script checks if the file has changed, and if not, aborts. In
either way it'll clean the file we added in the first, and it will of course
also still abort if the message is empty.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
-----END PGP SIGNATURE-----
More information about the bind10-dev