13 Aug 2012 redi   » (Master)

The GCC checkin policy requires a ChangeLog entry for each change, and that entry is usually also used as the commit message. I used to use a fairly crappy, homemade vim plugin to extract the first entry from a ChangeLog file into the editor buffer to use as the svn commit message. I decided to replace that vim plugin with a Git prepate-commit-msg hook that automatically prepares the commit message for me by extracting the first entry from each ChangeLog that is part of the commit.

As a cursory web search didn't find anything similar, I'm posting it here in case it's useful to anyone else.

$ cat .git/hooks/prepare-commit-msg
# Hook script to prepare the commit log message from the first
# entry in each modified ChangeLog being committed.

set -e

[[ "$2,$3" == 'merge,' ]] && exit

awk -f $0.awk $(git status -s | awk '/^M .*ChangeLog/{print $NF}') > $tmpf
sed 1d $1 >> $tmpf
mv $tmpf $1

$ cat .git/hooks/prepare-commit-msg.awk
# When there is more than one ChangeLog in the commit, precede
# the entry by the directory name.
FNR == 1 && ARGC > 2 {
printf "%s:\n\n", gensub("/ChangeLog$", "", "", FILENAME)

# Save the first line until we know if we want to print it.
FNR == 1 {

# If second line is blank there is only one patch author, omit it.
FNR == 2 && /^$/ {

# If second line is not blank there are multiple authors, print them.
FNR == 2 && /^./ {
print line1

# Stop processing the file at the next entry.
FNR > 3 && /^20[1-9][0-9]-[0-1][1-9]-[0-3][0-9] / {

# Otherwise, just print the line.
FNR > 2 {

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!