bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

yet another git trick


From: Paolo Bonzini
Subject: yet another git trick
Date: Wed, 28 May 2008 18:36:15 +0200
User-agent: Thunderbird 2.0.0.14 (Macintosh/20080421)

Newer versions of git have my patch for a prepare-commit-msg hook. The hook modifies the commit message before it is shown in the editor. This implementation of the hook does two things, which I found useful for GNU projects: 1) build a commit message template based on modified ChangeLog files; 2) comment out the "Conflicts:" part of the merge commits, so that it is shown but not stored forever.

Personally, I think this is a good alternative to making ChangeLog files automatically from the VCS logs.

Drop it in .git/hooks/prepare-commit-msg and make it executable!

Paolo


#!/bin/sh

make_changelog ()
{
  git diff "$@" -- \
   `git diff "$@" --name-status -r | \
        awk '/ChangeLog/ { print substr ($0, 3) }'` | sed -n \
    -e '/^@@/,/^+/ {' \
    -e '  s/^ //p' \
    -e '  t' \
    -e '}' \
    -e '/^diff/,/^@@/ {' \
    -e '  s/^diff --git a\/\(.*\)\/ChangeLog[^ ]* b\/.*/\1:/p' \
    -e '  tdummy' \
    -e '  :dummy' \
    -e '  d' \
    -e '}' \
    -e 's/^+//p' \
    -e 't'
}

case "$2${3+ }$3" in
  merge)
    sed -i '/^Conflicts:/,/#/!b;s/^/# &/;s/^# #/#/' "$1" ;;

  "")
    (echo; echo; make_changelog --cached; grep '^.' "$1") > "$1".tmp
    mv "$1".tmp "$1" ;;

  *) ;;
esac




reply via email to

[Prev in Thread] Current Thread [Next in Thread]