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

Re: Destructive pre-commit behaviour and "--all"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2023, 21:58 UTC
Message-ID
<xmqqfs9wcush.fsf@gitster.g>
In-Reply-To
<CAPx1GvfFrUQBDnJ9QYue91ScZb9ctB+tWv2S+pcprVC7dTgdxg@mail.gmail.com>
Chris Torek <chris.torek@gmail.com> writes:
Show 5 quoted lines
> It would in theory be possible for Git to load *the* index twice,
> once before and once after the hook, and compare them to see what
> changed, then perhaps try to use that change to update the
> additional indices.  That would be a pretty big change, but if it
> were done right, it might get what you want.

FYI, we tried not to do the extra re-reading, because pre-commit hook was designed to be a mechanism to allow users to validate, but not correct, what gets committed. As the system originally was designed, users who correctly use Git would *not* be modifying the index. Because it is an error to modify the index in the hook, (1) re-reading the index just in case the user commits such a mistake is waste of resources, and (2) checking the index to make sure it did not change before and after invoking the hook, again, is also waste of resources.

It may have been a mistake that we re-read the index in some case, which adds to the confusion, but not others.

Previous: Chris TorekNext: Jan Rüegg
Message 4 of 5 in “Destructive pre-commit behaviour and "--all"”
  1. Jan RüeggMar 22, 2023
  2. Chris TorekMar 22, 2023
  3. Chris TorekMar 22, 2023
  4. Junio C HamanoMar 22, 2023
  5. Jan RüeggMar 28, 2023

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.