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

Re: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2019, 01:18 UTC
Message-ID
<xmqqmumc69hf.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CANFDZM68A96YprMKhaHNfPRAtK18ad6Bo9=uesxHN=-tLONn=g@mail.gmail.com>
Fernando Chorney <djsbx@djsbx.com> writes:
Show 10 quoted lines
> Hmm looks like I forgot to send my reply to this back to the mailing list.
>
> "Hmm, so I currently have it set to run vim as my commit editor, and
> enter the message in there most of the time. I can definitely see
> output from the hook into the shell before my vim editor loads up that
> shows me the diff and lets me add in the commit message. This leads me
> to believe that the pre-commit hook is being run before the editor
> (with the diff) pops up."
>
> Does anybody else have any insight to this issue?

I do not know if it counts as an insight, but the pre-* hooks, not limited to pre-commit, were invented for the purpose of validating the input to an operation so that the hooks can _reject_ if the outcome anticipated does not satisfy project's conventions; the purpose they were invented was not because the operations wanted to allow the input to them. So attempting to modify the tree in pre-commit hook, for example, is outside the scope of its design and I wouldn't be surprised if you get an unexpected result.

Previous: Fernando Chorney
Message 4 of 4 in “git commit --verbose shows incorrect diff when pre-commit hook is used to modify files”
  1. Fernando ChorneyFeb 11, 2019
  2. Sergey LukashevFeb 11, 2019
  3. Fernando ChorneyFeb 26, 2019
  4. Junio C HamanoMar 3, 2019

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.