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

Re: precommit hook broken with "git commit <filename>"

From
C. Scott Ananian <cscott@laptop.org>
Date
Apr 12, 2011, 23:09 UTC
Message-ID
<BANLkTimm0CBP_vX1ZFoyLa7QR5qgnCgZKw@mail.gmail.com>
In-Reply-To
<7vvcyjnpvj.fsf@alter.siamese.dyndns.org>
On Tue, Apr 12, 2011 at 5:04 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> "C. Scott Ananian" <cscott@laptop.org> writes:
>
>> It appears that "git commit <filename>" breaks the git precommit hook.
>>  Every other git command updates the index to make the
>> commit-about-to-be-made before running the precommit hook, and indeed
>> the 'pre-commit.sample' distributed with git assumes that the index
>> reflects the commit.  However, in the case of "git commit <filename>"
>> the man page states "the commit will ignore changes staged in the
>> index, and instead record the current content of the listed files
>> (which must already be known to git)".
>
> Doesn't the command call the pre-commit hook with GIT_INDEX_FILE
> environment set to the temporary index used to create the (partial)
> commit?  The sample pre-commit hook runs "diff --cached" between that
> index and HEAD (or the empty tree), and should show the change about to be
> committed.

Thanks for the quick answer. You're right, of course. Our tests were subtly broken. Now that we understand how it's supposed to work, everything looks fine.

Great work on git, btw.  Yet another case where something I think
might be broken turns out to be working correctly (and smartly) all
along, or was recently fixed, etc...
 --scott
Previous: Junio C Hamano
Message 3 of 3 in “precommit hook broken with "git commit <filename>"”
  1. C. Scott AnanianApr 12, 2011
  2. Junio C HamanoApr 12, 2011
  3. C. Scott AnanianApr 12, 2011

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.