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

Re: prepare-commit-msg hook during rebase

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Apr 15, 2024, 14:01 UTC
Message-ID
<bf27ed3a-dc6c-4716-95c6-9e6c60604bd3@gmail.com>
In-Reply-To
<CAA19uiQip=EsbT8uQCs+98brYSTbOqyHX1ZBhssi4df3dZmZ6Q@mail.gmail.com>
Hi Michael
On 15/04/2024 11:36, Michael J Gruber wrote:
Show 28 quoted lines
> Hi there
> 
> For a while now, I thought I was using prepare-commit-msg hook wrong
> but finally took the time to analyse this further. Per the doc, the
> hook receives the source of the commit message as $2
> (message/template/merge/squash/commit or empty).
> 
> I notice the following with `rebase -i`:
> - When rb applies a patch to be edited/reworded, the hook is called
> with `commit` as the message source.
> - When rb applies a patch merely to be picked, the hook is called with
> `message` as the message source.
> 
> The latter also happens when non-interactive rebase applies commits.
> 
> I find this confusing for two reasons:
> - Whether edit/reword or pick, there is always a commit being applied,
> and it's the source of the message. So why not `commit` in both cases?
> - The doc says that `message` is for inputs from `-m` or `-F`. So,
> certainly this should not apply when the message comes from a picked
> commit.
> 
> Also, I'm not sure whether the claim about `-m` is true, but that's
> another issue; we even might want to distinguish between `-m` and `-F`
> here.
> 
> Does the source `message` during rb pick occur due to an
> implementation detail, maybe since the rewrite to sequencer?

All of the hook behavior in rebase is an accident of the implementation and stems from the scripted implementation. I'm not sure if the source passed to the hook has changed over time but it is quite possible that it has. I agree "commit" would be a more logical source. Personally I'm not sure it makes sense to run this hook for ordinary picks, though perhaps it makes sense to run it when the message is to be edited. Do you have a use for this hook while rebasing or are you just confused by the source argument?

Best Wishes
Phillip
> Cheers
> Michael
> 
Previous: Michael J GruberNext: Michael J Gruber
Message 2 of 3 in “prepare-commit-msg hook during rebase”
  1. Michael J GruberApr 15, 2024
  2. Phillip WoodApr 15, 2024
  3. Michael J GruberApr 15, 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.