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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 2, 2025 at 5:31 PM Junio C Hamano <gitster@xxxxxxxxx> 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
&lt;gitster@xxxxxxxxx&gt; 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 &lt;<a
href="mailto:phillip.wood123@xxxxxxxxx";
target="_blank">phillip.wood123@xxxxxxxxx</a>&gt; writes:<br>
<br>
&gt;&gt; git add --update -- ':(exclude)foo'<br>
&gt;&gt; This results in:<br>
&gt;&gt; error: pathspec ':(exclude)foo' did not match any file(s)
known to git<br>
&gt;&gt; error: pathspec '.' did not match any file(s) known to git<br>
&gt; ...<br>
&gt; git add -u builtin ':(exclude)*.[ch]'<br>
&gt;<br>
&gt; which will never add any files (the builtin directory only contains<br>
&gt; '.c' and '.h' files). So I think maybe the bug is that we don't print<br>
&gt; an error when there are tracked files and an exclude pattern matches<br>
&gt; everything<br>
<br>
I have to disagree here.&nbsp; The "did not match" error is telling you<br>
this:<br>
<br>
&nbsp; &nbsp; You tried to tell me that you wanted to add something, but you<br>
&nbsp; &nbsp; didn't enumerate what to add in concrete terms.&nbsp;
You instead<br>
&nbsp; &nbsp; gave me pathspec, so I tried to see if there are paths that<br>
&nbsp; &nbsp; match these patterns.&nbsp; This pattern did not produce
any match<br>
&nbsp; &nbsp; so out of this pattern came no additions (even though other<br>
&nbsp; &nbsp; 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.&nbsp; If I said<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; 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.&nbsp; I didn't want to add it, even if it<br>
existed, and it turned out to be missing.&nbsp; 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>





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux