* [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present @ 2025-05-27 8:14 Piotr Siupa 2025-06-02 10:07 ` Phillip Wood 0 siblings, 1 reply; 5+ messages in thread From: Piotr Siupa @ 2025-05-27 8:14 UTC (permalink / raw) To: git I found a regression in version 2.45.0. (It's still present in the current next - 2.49.0.1266.g31b7d2e469; earlier versions work fine.) When you run "git add --update" with an exclude pathspec on an empty repository, the command fails, showing an error about not being able to find the specified files. This happens only if the repository contains no files. Adding any files (even with "git add -N") or making a non-empty commit fixes the issue, regardless of whether the added files match the exclude pathspec or not. Way to reproduce: git init 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present 2025-05-27 8:14 [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present Piotr Siupa @ 2025-06-02 10:07 ` Phillip Wood 2025-06-02 15:31 ` Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: Phillip Wood @ 2025-06-02 10:07 UTC (permalink / raw) To: Piotr Siupa, git Hi Piotr On 27/05/2025 09:14, Piotr Siupa wrote: > I found a regression in version 2.45.0. (It's still present in the > current next - 2.49.0.1266.g31b7d2e469; earlier versions work fine.) So it 2.44.0 there is no error message? > When you run "git add --update" with an exclude pathspec on an empty > repository, the command fails, showing an error about not being able > to find the specified files. > This happens only if the repository contains no files. Adding any > files (even with "git add -N") or making a non-empty commit fixes the > issue, regardless of whether the added files match the exclude > pathspec or not. > > Way to reproduce: > git init > 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 I agree this is inconsistent with what happens if there are tracked files but I wonder if it is actually better to print an error message when an exclude pattern excludes all the files. We do print an error for git add -u does-not-exist because it does not match any file but not with git add -u ':(exclude)*' or 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 Best Wishes Phillip ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present 2025-06-02 10:07 ` Phillip Wood @ 2025-06-02 15:31 ` Junio C Hamano 2025-06-10 9:41 ` Piotr Siupa 0 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2025-06-02 15:31 UTC (permalink / raw) To: Phillip Wood; +Cc: Piotr Siupa, git Phillip Wood <phillip.wood123@gmail.com> writes: >> 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present 2025-06-02 15:31 ` Junio C Hamano @ 2025-06-10 9:41 ` Piotr Siupa 2025-06-10 9:45 ` Piotr Siupa 0 siblings, 1 reply; 5+ messages in thread From: Piotr Siupa @ 2025-06-10 9:41 UTC (permalink / raw) To: Junio C Hamano; +Cc: Phillip Wood, git On Mon, Jun 2, 2025 at 5:31 PM Junio C Hamano <gitster@pobox.com> wrote: > 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. [...] That would be my interpretation too. I mostly use the negative patterns for scripting. In scripts, unmatched negative patterns are more the rule than an exception, since you have to take into account all possible exclusions, without the foreknowledge of what will actually be present in the repository. From my experience, a failing command is never what you want in such situations. (For now, I added "--ignore-errors" to the script I'm writing and I hope this won't cause any bugs related to positive patterns.) Another thing to consider is that if the behavior of non-matching exclude patterns was changed now, it would break a lot of existing scripts that rely on the current behavior. <br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, Jun 2, 2025 at 5:31 PM Junio C Hamano <gitster@pobox.com> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Phillip Wood <<a href="mailto:phillip.wood123@gmail.com" target="_blank">phillip.wood123@gmail.com</a>> writes:<br> <br> >> git add --update -- ':(exclude)foo'<br> >> This results in:<br> >> error: pathspec ':(exclude)foo' did not match any file(s) known to git<br> >> error: pathspec '.' did not match any file(s) known to git<br> > ...<br> > git add -u builtin ':(exclude)*.[ch]'<br> ><br> > which will never add any files (the builtin directory only contains<br> > '.c' and '.h' files). So I think maybe the bug is that we don't print<br> > an error when there are tracked files and an exclude pattern matches<br> > everything<br> <br> I have to disagree here. The "did not match" error is telling you<br> this:<br> <br> You tried to tell me that you wanted to add something, but you<br> didn't enumerate what to add in concrete terms. You instead<br> gave me pathspec, so I tried to see if there are paths that<br> match these patterns. This pattern did not produce any match<br> so out of this pattern came no additions (even though other<br> patterns may have contributed to other additions).<br> <br> I think the "'.' did not match any file(s)" in the first example<br> makes perfect sense, but complaining about negative patterns that<br> did not match does not make much sense to me. If I said<br> <br> git add -- \*.c ':!auto-generated.c'<br> <br> and there is no auto-generated.c file (yet) in this working tree,<br> that is a happy outcome. I didn't want to add it, even if it<br> existed, and it turned out to be missing. It would become annoying<br> pretty quickly if we started complaining a pattern in .gitignore<br> that did not match anything, and complaining against "you gave me an<br> exclude pathspec pattern that matched nothing" feels pretty similar<br> to me.<br> <br> Thanks.<br> <br> </blockquote></div> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present 2025-06-10 9:41 ` Piotr Siupa @ 2025-06-10 9:45 ` Piotr Siupa 0 siblings, 0 replies; 5+ messages in thread From: Piotr Siupa @ 2025-06-10 9:45 UTC (permalink / raw) To: Junio C Hamano; +Cc: Phillip Wood, git I'm sorry. I don't know what happened in the previous message. I've explicitly chosen the plain text mode and removed the unnecessary quoted text. I hope this mail will be normal. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-10 9:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-27 8:14 [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag "--update" is present Piotr Siupa 2025-06-02 10:07 ` Phillip Wood 2025-06-02 15:31 ` Junio C Hamano 2025-06-10 9:41 ` Piotr Siupa 2025-06-10 9:45 ` Piotr Siupa
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).