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

Re: [PATCH v3] add: support pre-add hook

From
Ben Knoble <ben.knoble@gmail.com>
Date
Mar 4, 2026, 09:49 UTC
Message-ID
<33EBA399-2D24-48C7-AA1B-EBADF5E520D4@gmail.com>
In-Reply-To
<xmqqy0k8a4xo.fsf@gitster.g>
Show 14 quoted lines
> Le 3 mars 2026 à 18:06, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> "Chandra Kethi-Reddy via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
>> "git add" has no hook that lets users inspect what is about to be
>> staged. Users who want to reject certain paths or content must
>> wrap the command in a shell alias or wait for pre-commit, which
>> fires too late to prevent staging.
> 
> I do not think the above would convince readers that "preventing to
> add" is a worthy goal in the first place.  If you "git add foo" by
> mistake and wish you had this hook to prevent 'foo' from getting
> added ever, you can easily "git reset foo" to undo it.
It’s also not clear to me how the proposed hook could inspect “git add A B” and reject A but permit B, but maybe that’s a non-goals. 
Show 24 quoted lines
>> diff --git a/Documentation/githooks.adoc b/Documentation/githooks.adoc
>> index 056553788d..657e14d306 100644
>> --- a/Documentation/githooks.adoc
>> +++ b/Documentation/githooks.adoc
>> @@ -94,6 +94,36 @@ and is invoked after the patch is applied and a commit is made.
>> This hook is meant primarily for notification, and cannot affect
>> the outcome of `git am`.
>> 
>> +pre-add
>> +~~~~~~~
>> +
>> +This hook is invoked by linkgit:git-add[1], and can be bypassed with the
>> +`--no-verify` option. It is not invoked for `--interactive`, `--patch`,
>> +`--edit`, or `--dry-run`.
>> +
>> +It takes two parameters: the path to the index file for this invocation
> 
> Elsewhere you called these two files "arguments" but here you say
> "parameters".  Let's be consistent.
> 
>> +of `git add`, and the path to the lockfile containing the proposed
>> +index after staging. It does not read from standard input. If no index
>> +exists yet, the first parameter names a path that does not exist and
>> +should be treated as an empty index.
Saying “it [the hook] does not read from standard in” feels proscriptive rather than descriptive. Why couldn’t I write a short script that asked for confirmation of the paths being added via stdin?
Or perhaps we mean that Git does not write anything to the hook’s stdin… at which point I wonder if Junio’s “let’s not mention that we don’t do this unusual thing” applies? I haven’t looked at how the rest of our documentation describes hooks that aren’t fed input via stdin. 
Previous: Junio C HamanoNext: Phillip Wood
Message 13 of 26 in “add: support pre-add hook”
  1. add: support pre-add hookChandra Kethi-Reddy via GitGitGadget, Feb 10, 2026
  2. Junio C HamanoFeb 10, 2026
  3. Junio C HamanoFeb 10, 2026
  4. RE: add: support pre-add hookChandra, Feb 11, 2026
  5. add: support pre-add hookChandra Kethi-Reddy via GitGitGadget, Feb 11, 2026
  6. Junio C HamanoFeb 11, 2026
  7. ChandraFeb 11, 2026
  8. Junio C HamanoFeb 11, 2026
  9. ChandraFeb 11, 2026
  10. ChandraFeb 25, 2026
  11. add: support pre-add hookChandra Kethi-Reddy via GitGitGadget, Feb 27, 2026
  12. Junio C HamanoMar 3, 2026
  13. Ben KnobleMar 4, 2026
  14. Phillip WoodMar 5, 2026
  15. add: support pre-add hookChandra, Mar 5, 2026
  16. Junio C HamanoMar 5, 2026
  17. add: support pre-add hookChandra Kethi-Reddy via GitGitGadget, Mar 5, 2026
  18. Adrian RatiuMar 5, 2026
  19. ChandraMar 5, 2026
  20. add: support pre-add hookChandra Kethi-Reddy via GitGitGadget, Mar 5, 2026
  21. Adrian RatiuMar 5, 2026
  22. ChandraMar 5, 2026
  23. Junio C HamanoMar 5, 2026
  24. ChandraMar 6, 2026
  25. Phillip WoodMar 13, 2026
  26. Phillip WoodMar 5, 2026

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.