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

Re: Git not commiting anything if file created and "git add"ed in pre-commit hook is the only file in the staging area

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 30, 2021, 16:44 UTC
Message-ID
<4c88e2ae-e42f-491a-2b97-aa1f92c392d5@kdbg.org>
In-Reply-To
<c5507ba6-6e31-b143-9791-0bcff54acb64@gmx.net>
Am 30.10.21 um 15:21 schrieb Peter Hunkeler:
> Pardon my ignorance, but I'm unlear as to how to proceed further with my
> issue.
> What is the proper process to report a bug, and get a consense whether
> it is accepted or rejected?

Writing a message to this mailing list is all the process that exists. You brought forward arguments in a civil manner why you think the current behavior is not correct. That's appreciated. However, it doesn't automatically mean that something will be changed.

In your particular case...
Show 18 quoted lines
> Am 28.10.2021 um 14:08 schrieb Peter Hunkeler:
>> Am 28.10.2021 um 00:07 schrieb brian m. carlson:
>>> I should point out here that it isn't intended for pre-commit hooks to
>>> be used this way; they're intended to verify that the commit meets some
>>> standards, not to modify it, although it is of course possible to do.
>>>
>> I can accept that comment. However:
>>
>> - wouldn't you agree that git should work consistently? It does not in
>> this case. If there is anything to be commited in the index, then the
>> "git add" from within the pre-commit hook *is* respected in this commit.
>> If there is *nothing* to be commited, except from what was added by the
>> pre-commit exit, then it is ignored *for this commit*, but it is added
>> and will be commited next time. This is inconsistent behaviour.
>>
>> - if the decision will be *not* to allow adding from within a pre-commit
>> hook, then the "git add" should be rejected. And the documentation
>> should say so.

... it is clearly stated (and brian repeated it) that the pre-commit hook is intended to check the commit for "correctness" (whatever that means for the project). `git add` is not automatically forbidden, because it would be an unreasonable engineering effort to forbid things that "do not merely check" the commit. (What if a user has to use `git add` as part of some exotic check? For example, it is possible to `git add` to some temporary throw-away index that is different from the one that is about to be committed.)

Even though the documentation does not say explicitly that the commit must not be changed, it is implicit in the stated intent (that the commit is only checked). Depending on that some particular behavior works for you sometimes is then your own business, and when it breaks you get to keep both parts.

In conclusion, the pre-commit hook behaves as designed and nothing has to be changed.

-- Hannes
Previous: Peter HunkelerNext: Junio C Hamano
Message 7 of 9 in “Git not commiting anything if file created and "git add"ed in pre-commit hook is the only file in the staging area”
  1. Peter HunkelerOct 27, 2021
  2. brian m. carlsonOct 27, 2021
  3. Jeff KingOct 27, 2021
  4. Junio C HamanoOct 28, 2021
  5. Peter HunkelerOct 28, 2021
  6. Peter HunkelerOct 30, 2021
  7. Johannes SixtOct 30, 2021
  8. Junio C HamanoOct 30, 2021
  9. Peter HunkelerNov 2, 2021

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.