git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-commit: add a prepare-commit-msg hook

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jan 18, 2008, 16:37 UTC
Message-ID
<4790D5CF.8000602@gnu.org>
In-Reply-To
<alpine.LSU.1.00.0801181605020.5731@racer.site>
> In the message hook, just grep if the template was already added.  If it 
> was, just return.  If it was not, add it.

Ah, so you want me to always type ":q!" to exit and unnecessarily complicate the commit-msg hook. Cunning, but no, thanks.

I'll make an example.  This is my prepare-commit-msg hook:
diff_collect_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'
}
diff_collect_changelog --cached > /tmp/foo$$
cat "$GIT_COMMIT_MSG" >> /tmp/foo$$ && \
   mv /tmp/foo$$ "$GIT_COMMIT_MSG"
rm -f /tmp/foo$$

or something like that. The alternative I see would be to start the vi editing session with "!!make_changelog --cached". So I thought about having an hook that runs the command for me. Do you have better ideas?

Paolo
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 5 of 23 in “git-commit: add a prepare-commit-msg hook”
  1. git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 18, 2008
  2. Johannes SchindelinJan 18, 2008
  3. Paolo BonziniJan 18, 2008
  4. Johannes SchindelinJan 18, 2008
  5. Paolo BonziniJan 18, 2008
  6. Johannes SchindelinJan 18, 2008
  7. Paolo BonziniJan 18, 2008
  8. Benoit SigoureJan 18, 2008
  9. Alex RiesenJan 18, 2008
  10. Paolo BonziniJan 18, 2008
  11. Alex RiesenJan 18, 2008
  12. Junio C HamanoJan 18, 2008
  13. Paolo BonziniJan 19, 2008
  14. Johannes SchindelinJan 19, 2008
  15. Benoit SigoureJan 19, 2008
  16. Paolo BonziniJan 19, 2008
  17. Junio C HamanoJan 20, 2008
  18. Paolo BonziniJan 21, 2008
  19. Johannes SchindelinJan 21, 2008
  20. Paolo BonziniJan 21, 2008
  21. Johannes SchindelinJan 21, 2008
  22. Paolo BonziniJan 21, 2008
  23. Junio C HamanoJan 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.