All of lore.kernel.org
 help / color / mirror / Atom feed
* obsolete index in wt_status_print after pre-commit hook runs
@ 2016-07-15 16:34 Andrew Keller
  2016-07-15 17:02 ` Junio C Hamano
  2016-07-15 20:30 ` Andrew Keller
  0 siblings, 2 replies; 13+ messages in thread
From: Andrew Keller @ 2016-07-15 16:34 UTC (permalink / raw)
  To: Git List

Hi everyone,

I have observed an interesting scenario.  Here are example reproduction steps:

1. new repository
2. create new pre-commit hook that invokes `git mv one two`
3. touch one
4. git add one
5. git commit

Expected outcome: In the commit message template, I expect to see “Changes to be committed: new file: two"

Found outcome: In the commit message template, I see “Changes to be committed: new file: one"

This behavior seems to be reproducible in versions 2.9.1, 2.8.1, 2.0.0, and 1.6.0.

Skip the next 3 paragraphs if you are in a hurry.

I pulled out the source for version 2.9.1 and briefly skimmed how run_commit and
prepare_to_commit work.  It seems that Git already understands that a pre-commit
hook can change the index, and it rereads the index before running the
prepare-commit-msg hook: https://github.com/git/git/blob/v2.9.1/builtin/commit.c#L941-L951

During the prepare-commit-msg hook, it seems that the index (according to Git
commands) is correct and up-to-date, but the textual message inside the commit
message template is out-of-date (it references the file `one` as a change to be
committed).

In builtin/commit.c, it seems that the commit message template is rendered
immediately after the pre-commit hook is ran, and immediately before the index is
reread.  If I move the small block of code that rereads the index up, to just after
the pre-commit hook is ran, the commit message template seems to be as I would
expect, both in .git/COMMIT_EDITMSG during the prepare-commit-msg hook and
in the editor for the commit message itself.

I am putting together a 2-patch series that includes a failing test, and then this
change (which fixes the test), but while I do that, I figure I may as well ping the
community to make sure that this behavior is not intentional.  I’d wager that this
change is for the better, but since this behavior has been around so long (I stopped
checking at 1.6.0), it doesn’t hurt to make sure.

Any comments, concerns, or advice?

Thanks,
 - Andrew Keller


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-08-05 13:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15 16:34 obsolete index in wt_status_print after pre-commit hook runs Andrew Keller
2016-07-15 17:02 ` Junio C Hamano
2016-07-15 17:20   ` Andrew Keller
2016-07-15 17:28     ` Junio C Hamano
2016-07-15 17:42       ` Andrew Keller
2016-07-15 20:30 ` Andrew Keller
2016-07-15 21:19   ` Junio C Hamano
2016-07-15 22:03     ` Junio C Hamano
2016-07-16  2:39       ` Andrew Keller
2016-08-03 18:25       ` Andrew Keller
2016-08-04 16:45         ` Junio C Hamano
2016-08-05 13:22           ` Andrew Keller
2016-07-16  2:23     ` Andrew Keller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.