git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael J Gruber <git@grubix.eu>
To: Git List <git@vger.kernel.org>,
	Phillip Wood <phillip.wood123@gmail.com>,
	phillip.wood@dunelm.org.uk
Subject: Re: prepare-commit-msg hook during rebase
Date: Mon, 15 Apr 2024 16:32:35 +0200	[thread overview]
Message-ID: <171319155563.9055.10218254775303206647.git@grubix.eu> (raw)
In-Reply-To: <bf27ed3a-dc6c-4716-95c6-9e6c60604bd3@gmail.com>

Phillip Wood venit, vidit, dixit 2024-04-15 16:01:31:
> Hi Michael
> 
> On 15/04/2024 11:36, Michael J Gruber wrote:
> > 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?

It is run during a rebase, and I don't have a use for it there, in
particular not for picked commits which I do not amend. That is what
triggered my investigation (unintended runs).

In fact, my hook messes up commits during a rebase if I run rebase from
a subdirectory, and I am sure that it didn't (quite) some time in the
past. But this can have several reasons:

- prepare-commit-msg was not run for rebase picks at all in the past
- prepare-commit-msg was run with source "commit" in the past
- prepare-commit-msg was run from the topdir (not cwd) in the past

I can avoid the mess by detecting the rebase state in the hook (or
cd'ing to topdir before the rebase), but I'm wondering what changed and
what is the right behaviour (to which I would adjust, of course).

Also, looking at sequencer.c from line 6545, sequencer_determine_whence()
looks funny: FROM_CHERRY_PICK_MULTI from the first if will always be
overwritten by the second if/else. I'm not saying this is strictly
related, but we do have untested code paths in that area. whence is part
of what makes commit decide on hooks being run and arguments passed to
them.

Michael


      reply	other threads:[~2024-04-15 14:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 10:36 prepare-commit-msg hook during rebase Michael J Gruber
2024-04-15 14:01 ` Phillip Wood
2024-04-15 14:32   ` Michael J Gruber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=171319155563.9055.10218254775303206647.git@grubix.eu \
    --to=git@grubix.eu \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood123@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).