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

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

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jan 21, 2008, 14:27 UTC
Message-ID
<2885c7896ba72adee6bc5c9e2210a8881904f601.head.git.bonzini@gnu.org>

This series of patches adds a prepare-commit-msg hook. The prepare-commit-msg hook is run whenever a "fresh" commit message is prepared, just before it is shown in the editor (if it is). It can modify the commit message in-place and/or abort the commit. I implemented Alex Riesen's suggestion to tell the hook where the message came from, and now run the hook even if the editor is not run.

Patches 1 and 2 are small changes. Patch 1 changes run_hook to accept a variable-length NULL-terminated list of arguments. Patch 2 forces GIT_EDITOR to : if editor will not be launched; this is the simplest way I found to tell the prepare-commit-msg hook whether the editor will be launched.

Patch 3 is bigger; it refactors parts of git-commit to do all the log message processing at the same time. Currently the message is prepared soon, but only edited after the first part of the commit object is prepared. This simplifies a little the code for part 4.

Part 4 actually adds the hook, including documentation and testcases. The hook takes two parameters. The first is the source of the commit message (detailed more in the commit message and in the docs), which is either an English word or a commit SHA1. The second parameter if the name of the file that the commit log message.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
Next: Paolo Bonzini
Message 1 of 13 in “git-commit: add a prepare-commit-msg hook”
  1. git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  2. 1/4 git-commit: support variable number of hook argumentsPaolo Bonzini, Jan 21, 2008
  3. Johannes SchindelinFeb 4, 2008
  4. Junio C HamanoFeb 5, 2008
  5. 2/4 git-commit: set GIT_EDITOR=: if editor will not be launchedPaolo Bonzini, Jan 21, 2008
  6. 4/4 git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  7. Junio C HamanoFeb 5, 2008
  8. 3/4 git-commit: Refactor creation of log message.Paolo Bonzini, Jan 21, 2008
  9. Johannes SchindelinFeb 4, 2008
  10. Paolo BonziniFeb 4, 2008
  11. Junio C HamanoFeb 5, 2008
  12. Junio C HamanoFeb 5, 2008
  13. Paolo BonziniFeb 5, 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.