{"thread":{"id":"63530","subject":"[BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","startedAt":"2025-05-27T08:14:27Z","lastAt":"2025-06-10T09:46:03Z","messageCount":5,"participants":["Piotr Siupa","Phillip Wood","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"518961","messageId":"CAPM0=yCcOAGsUE8tX-o8ioihr+oWrORD6Tz=WH1OnmhpO+uqrA@mail.gmail.com","threadId":"63530","inReplyTo":null,"subject":"[BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","fromName":"Piotr Siupa","fromEmail":"piotrsiupa@gmail.com","sentAt":"2025-05-27T08:14:10Z","receivedAt":"2025-05-27T08:14:27Z","isPatch":false,"sender":{"key":"piotrsiupa@gmail.com","avatar":"https://gravatar.com/avatar/5970da465a147bda2b821a29e966ed328cca93067a42d05cf33ee38aac4acd6f?d=mp&s=160"},"body":"I found a regression in version 2.45.0. (It's still present in the\ncurrent next - 2.49.0.1266.g31b7d2e469; earlier versions work fine.)\n\nWhen you run \"git add --update\" with an exclude pathspec on an empty\nrepository, the command fails, showing an error about not being able\nto find the specified files.\nThis happens only if the repository contains no files. Adding any\nfiles (even with \"git add -N\") or making a non-empty commit fixes the\nissue, regardless of whether the added files match the exclude\npathspec or not.\n\nWay to reproduce:\ngit init\ngit add --update -- ':(exclude)foo'\n\nThis results in:\nerror: pathspec ':(exclude)foo' did not match any file(s) known to git\nerror: pathspec '.' did not match any file(s) known to git\n"},{"id":"519407","messageId":"e790367c-6777-4b4b-97f1-3b3a2cbdb177@gmail.com","threadId":"63530","inReplyTo":"CAPM0=yCcOAGsUE8tX-o8ioihr+oWrORD6Tz=WH1OnmhpO+uqrA@mail.gmail.com","subject":"Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-06-02T10:07:17Z","receivedAt":"2025-06-02T10:07:20Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Piotr\n\nOn 27/05/2025 09:14, Piotr Siupa wrote:\n> I found a regression in version 2.45.0. (It's still present in the\n> current next - 2.49.0.1266.g31b7d2e469; earlier versions work fine.)\n\nSo it 2.44.0 there is no error message?\n\n> When you run \"git add --update\" with an exclude pathspec on an empty\n> repository, the command fails, showing an error about not being able\n> to find the specified files.\n> This happens only if the repository contains no files. Adding any\n> files (even with \"git add -N\") or making a non-empty commit fixes the\n> issue, regardless of whether the added files match the exclude\n> pathspec or not.\n> \n> Way to reproduce:\n> git init\n> git add --update -- ':(exclude)foo'\n> \n> This results in:\n> error: pathspec ':(exclude)foo' did not match any file(s) known to git\n> error: pathspec '.' did not match any file(s) known to git\n\nI agree this is inconsistent with what happens if there are tracked \nfiles but I wonder if it is actually better to print an error message \nwhen an exclude pattern excludes all the files. We do print an error for\n\ngit add -u does-not-exist\n\nbecause it does not match any file but not with\n\ngit add -u ':(exclude)*'\n\nor\n\ngit add -u builtin ':(exclude)*.[ch]'\n\nwhich will never add any files (the builtin directory only contains '.c' \nand '.h' files). So I think maybe the bug is that we don't print an \nerror when there are tracked files and an exclude pattern matches everything\n\nBest Wishes\n\nPhillip\n"},{"id":"519474","messageId":"xmqq34ciupll.fsf@gitster.g","threadId":"63530","inReplyTo":"e790367c-6777-4b4b-97f1-3b3a2cbdb177@gmail.com","subject":"Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-06-02T15:31:50Z","receivedAt":"2025-06-02T15:31:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n>> git add --update -- ':(exclude)foo'\n>> This results in:\n>> error: pathspec ':(exclude)foo' did not match any file(s) known to git\n>> error: pathspec '.' did not match any file(s) known to git\n> ...\n> git add -u builtin ':(exclude)*.[ch]'\n>\n> which will never add any files (the builtin directory only contains\n> '.c' and '.h' files). So I think maybe the bug is that we don't print\n> an error when there are tracked files and an exclude pattern matches\n> everything\n\nI have to disagree here.  The \"did not match\" error is telling you\nthis:\n\n    You tried to tell me that you wanted to add something, but you\n    didn't enumerate what to add in concrete terms.  You instead\n    gave me pathspec, so I tried to see if there are paths that\n    match these patterns.  This pattern did not produce any match\n    so out of this pattern came no additions (even though other\n    patterns may have contributed to other additions).\n\nI think the \"'.' did not match any file(s)\" in the first example\nmakes perfect sense, but complaining about negative patterns that\ndid not match does not make much sense to me.  If I said\n\n\tgit add -- \\*.c ':!auto-generated.c'\n\nand there is no auto-generated.c file (yet) in this working tree,\nthat is a happy outcome.  I didn't want to add it, even if it\nexisted, and it turned out to be missing.  It would become annoying\npretty quickly if we started complaining a pattern in .gitignore\nthat did not match anything, and complaining against \"you gave me an\nexclude pathspec pattern that matched nothing\" feels pretty similar\nto me.\n\nThanks.\n\n"},{"id":"520030","messageId":"CAPM0=yCScvtJ=v=xZeH6ZqGtnuGeQbHn+Dj6OCiP4Ci=z_Hf+g@mail.gmail.com","threadId":"63530","inReplyTo":"xmqq34ciupll.fsf@gitster.g","subject":"Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","fromName":"Piotr Siupa","fromEmail":"piotrsiupa@gmail.com","sentAt":"2025-06-10T09:41:49Z","receivedAt":"2025-06-10T09:42:06Z","isPatch":false,"sender":{"key":"piotrsiupa@gmail.com","avatar":"https://gravatar.com/avatar/5970da465a147bda2b821a29e966ed328cca93067a42d05cf33ee38aac4acd6f?d=mp&s=160"},"body":"On Mon, Jun 2, 2025 at 5:31 PM Junio C Hamano <gitster@pobox.com> wrote:\n> I have to disagree here.  The \"did not match\" error is telling you\n> this:\n>\n>     You tried to tell me that you wanted to add something, but you\n>     didn't enumerate what to add in concrete terms.  You instead\n>     gave me pathspec, so I tried to see if there are paths that\n>     match these patterns.  This pattern did not produce any match\n>     so out of this pattern came no additions (even though other\n>     patterns may have contributed to other additions).\n>\n> I think the \"'.' did not match any file(s)\" in the first example\n> makes perfect sense, but complaining about negative patterns that\n> did not match does not make much sense to me. [...]\n\nThat would be my interpretation too.\n\nI mostly use the negative patterns for scripting.\nIn scripts, unmatched negative patterns are more the rule than an\nexception, since you have to take into account all possible\nexclusions, without the foreknowledge of what will actually be present\nin the repository. From my experience, a failing command is never what\nyou want in such situations. (For now, I added \"--ignore-errors\" to\nthe script I'm writing and I hope this won't cause any bugs related to\npositive patterns.)\n\nAnother thing to consider is that if the behavior of non-matching\nexclude patterns was changed now, it would break a lot of existing\nscripts that rely on the current behavior.\n<br><div class=\"gmail_quote gmail_quote_container\"><div dir=\"ltr\"\nclass=\"gmail_attr\">On Mon, Jun 2, 2025 at 5:31 PM Junio C Hamano\n&lt;gitster@pobox.com&gt; wrote:<br></div><blockquote\nclass=\"gmail_quote\" style=\"margin: 0px 0px 0px 0.8ex; border-left: 1px\nsolid rgb(204, 204, 204); padding-left: 1ex;\">Phillip Wood &lt;<a\nhref=\"mailto:phillip.wood123@gmail.com\"\ntarget=\"_blank\">phillip.wood123@gmail.com</a>&gt; writes:<br>\n<br>\n&gt;&gt; git add --update -- ':(exclude)foo'<br>\n&gt;&gt; This results in:<br>\n&gt;&gt; error: pathspec ':(exclude)foo' did not match any file(s)\nknown to git<br>\n&gt;&gt; error: pathspec '.' did not match any file(s) known to git<br>\n&gt; ...<br>\n&gt; git add -u builtin ':(exclude)*.[ch]'<br>\n&gt;<br>\n&gt; which will never add any files (the builtin directory only contains<br>\n&gt; '.c' and '.h' files). So I think maybe the bug is that we don't print<br>\n&gt; an error when there are tracked files and an exclude pattern matches<br>\n&gt; everything<br>\n<br>\nI have to disagree here.&nbsp; The \"did not match\" error is telling you<br>\nthis:<br>\n<br>\n&nbsp; &nbsp; You tried to tell me that you wanted to add something, but you<br>\n&nbsp; &nbsp; didn't enumerate what to add in concrete terms.&nbsp;\nYou instead<br>\n&nbsp; &nbsp; gave me pathspec, so I tried to see if there are paths that<br>\n&nbsp; &nbsp; match these patterns.&nbsp; This pattern did not produce\nany match<br>\n&nbsp; &nbsp; so out of this pattern came no additions (even though other<br>\n&nbsp; &nbsp; patterns may have contributed to other additions).<br>\n<br>\nI think the \"'.' did not match any file(s)\" in the first example<br>\nmakes perfect sense, but complaining about negative patterns that<br>\ndid not match does not make much sense to me.&nbsp; If I said<br>\n<br>\n&nbsp; &nbsp; &nbsp; &nbsp; git add -- \\*.c ':!auto-generated.c'<br>\n<br>\nand there is no auto-generated.c file (yet) in this working tree,<br>\nthat is a happy outcome.&nbsp; I didn't want to add it, even if it<br>\nexisted, and it turned out to be missing.&nbsp; It would become annoying<br>\npretty quickly if we started complaining a pattern in .gitignore<br>\nthat did not match anything, and complaining against \"you gave me an<br>\nexclude pathspec pattern that matched nothing\" feels pretty similar<br>\nto me.<br>\n<br>\nThanks.<br>\n<br>\n</blockquote></div>\n"},{"id":"520031","messageId":"CAPM0=yDe2gZhtQUX-uszbYYibMQrSbCf0c=hrqEiLp53VGk41w@mail.gmail.com","threadId":"63530","inReplyTo":"CAPM0=yCScvtJ=v=xZeH6ZqGtnuGeQbHn+Dj6OCiP4Ci=z_Hf+g@mail.gmail.com","subject":"Re: [BUG]: Non-matching exclude pathspec causes an error in empty repository when the flag \"--update\" is present","fromName":"Piotr Siupa","fromEmail":"piotrsiupa@gmail.com","sentAt":"2025-06-10T09:45:45Z","receivedAt":"2025-06-10T09:46:03Z","isPatch":false,"sender":{"key":"piotrsiupa@gmail.com","avatar":"https://gravatar.com/avatar/5970da465a147bda2b821a29e966ed328cca93067a42d05cf33ee38aac4acd6f?d=mp&s=160"},"body":"I'm sorry. I don't know what happened in the previous message. I've\nexplicitly chosen the plain text mode and removed the unnecessary\nquoted text. I hope this mail will be normal.\n"}]}