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

[BUG REPORT] git-gui invokes prepare-commit-msg hook incorrectly

From
brianmlyles <brianmlyles@gmail.com>
Date
Jul 5, 2024, 19:23 UTC
Message-ID
<17df67804ef7a3c8.df629cdadcf4ea15.524a056283063601@EPIC94403>

I noticed that commits from certain users were ending up in our repository with comment-like lines in the commit message. I traced the cause back to the combination of:

- Those users are using git-gui to make their commits
- A `prepare-commit-msg` hook is adding a dynamic commit message
  template using comment lines starting with `#`
- git-gui creates the commit in a way that circumvents the message
  washing similar to if one used `git commit -F`, but invokes the
  `prepare-commit-msg` hook without any additional arguments like
  "message" [1] that would tell the hook that `-F` is being used
[1]: https://git-scm.com/docs/githooks#_prepare_commit_msg

The result here is that even though the `prepare-commit-msg` hook is already correctly short-circuiting when given the "message" parameter, it is providing these comment lines when called by git-gui, and thus the commits have these comment lines in them.

This seems like a bug in git-gui. I see two fixes, but I'm not sure which is more correct:

- Have git-gui pass "message" as an argument to the
  `prepare-commit-msg` hook so that the hook knows that `-F`-like
  behavior is being used
- Have git-gui create the commit in a way that causes the message to be
  washed

The latter seems like it would be more consistent with other workflows where the user is seeing the message in an editor, so my instinct is that it would be the better fix.

-- 
Thank you,
Brian Lyles
Next: Eric Sunshine
Message 1 of 10 in “[BUG REPORT] git-gui invokes prepare-commit-msg hook incorrectly”
  1. brianmlylesJul 5, 2024
  2. Eric SunshineJul 5, 2024
  3. Sean AllredJul 5, 2024
  4. Eric SunshineJul 5, 2024
  5. Johannes SixtJul 6, 2024
  6. Junio C HamanoJul 6, 2024
  7. Johannes SixtJul 7, 2024
  8. Brian LylesJul 8, 2024
  9. Johannes SixtJul 8, 2024
  10. Oswald BuddenhagenAug 7, 2024

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.