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

Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 2, 2025, 15:31 UTC
Message-ID
<xmqq34ciupll.fsf@gitster.g>
In-Reply-To
<e790367c-6777-4b4b-97f1-3b3a2cbdb177@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 11 quoted lines
>> git add --update -- ':(exclude)foo'
>> This results in:
>> error: pathspec ':(exclude)foo' did not match any file(s) known to git
>> error: pathspec '.' did not match any file(s) known to git
> ...
> git add -u builtin ':(exclude)*.[ch]'
>
> which will never add any files (the builtin directory only contains
> '.c' and '.h' files). So I think maybe the bug is that we don't print
> an error when there are tracked files and an exclude pattern matches
> everything

I have to disagree here. The "did not match" error is telling you this:

    You tried to tell me that you wanted to add something, but you
    didn't enumerate what to add in concrete terms.  You instead
    gave me pathspec, so I tried to see if there are paths that
    match these patterns.  This pattern did not produce any match
    so out of this pattern came no additions (even though other
    patterns may have contributed to other additions).

I think the "'.' did not match any file(s)" in the first example makes perfect sense, but complaining about negative patterns that did not match does not make much sense to me. If I said

	git add -- \*.c ':!auto-generated.c'

and there is no auto-generated.c file (yet) in this working tree, that is a happy outcome. I didn't want to add it, even if it existed, and it turned out to be missing. It would become annoying pretty quickly if we started complaining a pattern in .gitignore that did not match anything, and complaining against "you gave me an exclude pathspec pattern that matched nothing" feels pretty similar to me.

Thanks.
Previous: Phillip WoodNext: Piotr Siupa
Message 3 of 5 in “[BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present”
  1. Piotr SiupaMay 27, 2025
  2. Phillip WoodJun 2, 2025
  3. Junio C HamanoJun 2, 2025
  4. Piotr SiupaJun 10, 2025
  5. Piotr SiupaJun 10, 2025

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.