{"thread":{"id":"64101","subject":"Is Git Add Supposed to Work Like This (git 2.50)?","startedAt":"2025-09-07T02:02:55Z","lastAt":"2025-09-09T21:01:40Z","messageCount":9,"participants":["Jon Forrest","K Jayatheerth","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"525696","messageId":"63045080-74d6-4835-9d9c-4d3558acdbfb@gmail.com","threadId":"64101","inReplyTo":null,"subject":"Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2025-09-07T02:02:53Z","receivedAt":"2025-09-07T02:02:55Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"(Linux fedora 6.16.4-200.fc42.x86_64)\n\nLet's say I have the file \"x\" in my working directory, but\nnot \"bogus_file\".\n\nIf I run\n\n\tgit add x bogus_file\n\nI get\n\n\tfatal: pathspec 'bogus_file' did not match any files\n\nThis is what I expect. However, if I look at what's in the index,\n\"x\" doesn't appear. The same thing happens if I specify 15\nvalid files followed by 1 invalid file.\n\nApparently the presence of even 1 invalid file invalidates\nthe whole 'git add' command, no matter how many valid files\nare included.\n\nIs this deliberate?\n\nCordially,\nJon Forrest\n\n"},{"id":"525705","messageId":"20250907081014.17466-1-jayatheerthkulkarni2005@gmail.com","threadId":"64101","inReplyTo":"63045080-74d6-4835-9d9c-4d3558acdbfb@gmail.com","subject":"Re Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"K Jayatheerth","fromEmail":"jayatheerthkulkarni2005@gmail.com","sentAt":"2025-09-07T08:10:14Z","receivedAt":"2025-09-07T08:10:27Z","isPatch":false,"sender":{"key":"jayatheerthkulkarni2005@gmail.com","avatar":"https://avatars.githubusercontent.com/u/148841023?v=4"},"body":"To answer very shortly, \"It is intended\"\n\nReason:\nI don't exactly know if I am pointing to the right code lines\n\nBut if you dig into builtin/add.c you will find these lines\n\n\t/*\n\t * Check the \"pathspec '%s' did not match any files\" block\n\t * below before enabling new magic.\n\t */\n\tparse_pathspec(&pathspec, 0,\n\t\t       PATHSPEC_PREFER_FULL |\n\t\t       PATHSPEC_SYMLINK_LEADING_PATH,\n\t\t       prefix, argv);\n\n\nIf you read the comment you will know this\nis already intented (the behaviour which you described)\n\n- Jayatheerth\n"},{"id":"525744","messageId":"20250907233456.GA1281511@coredump.intra.peff.net","threadId":"64101","inReplyTo":"63045080-74d6-4835-9d9c-4d3558acdbfb@gmail.com","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-09-07T23:34:56Z","receivedAt":"2025-09-07T23:35:06Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Sep 06, 2025 at 07:02:53PM -0700, Jon Forrest wrote:\n\n> Apparently the presence of even 1 invalid file invalidates\n> the whole 'git add' command, no matter how many valid files\n> are included.\n> \n> Is this deliberate?\n\nYes. The C code here goes back to f25933987f (builtin-add: warn on\nunmatched pathspecs, 2006-05-17), which is in turn adapting 45e48120bb\n(Detect misspelled pathspec to git-add, 2006-02-15) from the shell\nversion. Which is pulling the same feature from git-commit's bba319b5ce\n(commit: detect misspelled pathspec while making a partial commit.,\n2006-02-14). Which in turn from this thread:\n\n  https://lore.kernel.org/git/7vfymlr7n8.fsf@assigned-by-dhcp.cox.net/\n\nsounds like it came from cogito. I didn't follow the trail to the #git\narchives mentioned there. ;)\n\nInterestingly Pasky does mention that cogito behaved as you expected\n(quietly ignoring a single misspelling) and considered it a bug.\n\nI guess one could argue either way (though probably not at this point in\ntime, as switching behaviors would cause confusion). But one challenge\nwith \"partial success\" like this is that the exit code is binary. If we\nreturn \"0\" even though some items were ignored, callers may miss a\nfailure. If we return \"1\" even though some items were added, callers may\nnot realize they've mutated the state (and might need to rollback\ndepending on what they were trying to accomplish).\n\nI think Git's philosophy is along the lines of: if we are not sure your\ncommand was well-formed, do nothing. You can always re-issue the command\nwith a corrected set of arguments.\n\n-Peff\n"},{"id":"525966","messageId":"b8df3605-7afe-4121-ae50-095dfd671df9@gmail.com","threadId":"64101","inReplyTo":"20250907233456.GA1281511@coredump.intra.peff.net","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2025-09-09T16:00:34Z","receivedAt":"2025-09-09T16:00:37Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"\n\nOn 9/7/25 4:34 PM, Jeff King wrote:\n\n> I guess one could argue either way (though probably not at this point in\n> time, as switching behaviors would cause confusion). But one challenge\n> with \"partial success\" like this is that the exit code is binary. If we\n> return \"0\" even though some items were ignored, callers may miss a\n> failure. If we return \"1\" even though some items were added, callers may\n> not realize they've mutated the state (and might need to rollback\n> depending on what they were trying to accomplish).\n\nIf this were a big deal, which it isn't, I'd suggest a command line\nflag that says what to do if there's an invalid file specified on\nthe command line. One setting of the flag would result in the\ncurrent behavior and the other setting would result in all the\ninvalid file(s) being ignored and the valid file(s) being\nhandled normally.\n\nJon\n\n"},{"id":"525970","messageId":"109prte$j8b$1@ciao.gmane.io","threadId":"64101","inReplyTo":"b8df3605-7afe-4121-ae50-095dfd671df9@gmail.com","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2025-09-09T18:33:18Z","receivedAt":"2025-09-09T18:38:34Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"On 9/9/25 9:00 AM, Jon Forrest wrote:\n> \n> \n> If this were a big deal, which it isn't, I'd suggest a command line\n> flag that says what to do if there's an invalid file specified on\n> the command line. One setting of the flag would result in the\n> current behavior and the other setting would result in all the\n> invalid file(s) being ignored and the valid file(s) being\n> handled normally.\n\nNevermind. I should have checked the man page.\nThe '--ignore-errors' option already does this.\n\nSorry for the bother.\n\nJon\n\n\n"},{"id":"525971","messageId":"20250909184045.GA1912898@coredump.intra.peff.net","threadId":"64101","inReplyTo":"b8df3605-7afe-4121-ae50-095dfd671df9@gmail.com","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-09-09T18:40:45Z","receivedAt":"2025-09-09T18:40:49Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 09, 2025 at 09:00:34AM -0700, Jon Forrest wrote:\n\n> > I guess one could argue either way (though probably not at this point in\n> > time, as switching behaviors would cause confusion). But one challenge\n> > with \"partial success\" like this is that the exit code is binary. If we\n> > return \"0\" even though some items were ignored, callers may miss a\n> > failure. If we return \"1\" even though some items were added, callers may\n> > not realize they've mutated the state (and might need to rollback\n> > depending on what they were trying to accomplish).\n> \n> If this were a big deal, which it isn't, I'd suggest a command line\n> flag that says what to do if there's an invalid file specified on\n> the command line. One setting of the flag would result in the\n> current behavior and the other setting would result in all the\n> invalid file(s) being ignored and the valid file(s) being\n> handled normally.\n\nInterestingly there are a few --ignore-* options, including\n--ignore-missing, which I think does what you want. But it only works\nwith --dry-run. I didn't dig into the rationale.\n\n-Peff\n"},{"id":"525972","messageId":"20250909184231.GB1912898@coredump.intra.peff.net","threadId":"64101","inReplyTo":"109prte$j8b$1@ciao.gmane.io","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-09-09T18:42:31Z","receivedAt":"2025-09-09T18:42:32Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 09, 2025 at 11:33:18AM -0700, Jon Forrest wrote:\n\n> On 9/9/25 9:00 AM, Jon Forrest wrote:\n> > \n> > \n> > If this were a big deal, which it isn't, I'd suggest a command line\n> > flag that says what to do if there's an invalid file specified on\n> > the command line. One setting of the flag would result in the\n> > current behavior and the other setting would result in all the\n> > invalid file(s) being ignored and the valid file(s) being\n> > handled normally.\n> \n> Nevermind. I should have checked the man page.\n> The '--ignore-errors' option already does this.\n\nOops, I think our mails just crossed. I don't think --ignore-errors does\nquite what you want, though:\n\n  $ touch foo\n  $ git add foo bar\n  fatal: pathspec 'bar' did not match any files\n  $ git add --ignore-errors foo bar\n  fatal: pathspec 'bar' did not match any files\n  $ git status --porcelain\n  ?? foo\n\n-Peff\n"},{"id":"525994","messageId":"xmqqsegvtkgm.fsf@gitster.g","threadId":"64101","inReplyTo":"20250909184231.GB1912898@coredump.intra.peff.net","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-09-09T20:55:05Z","receivedAt":"2025-09-09T20:55:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Oops, I think our mails just crossed. I don't think --ignore-errors does\n> quite what you want, though:\n>\n>   $ touch foo\n>   $ git add foo bar\n>   fatal: pathspec 'bar' did not match any files\n>   $ git add --ignore-errors foo bar\n>   fatal: pathspec 'bar' did not match any files\n>   $ git status --porcelain\n>   ?? foo\n\nThe option is described like so:\n\n    --[no-]ignore-errors  just skip files which cannot be added because of errors\n\nI think \"because of errors\" is meant handle a sequence more like this:\n\n    $ date >foo ; date >bar\n    $ chmod a= foo\n    $ git add --ignore-errors foo bar\n    $ git diff --cached --name-only\n    bar\n\n\n"},{"id":"525995","messageId":"20250909210138.GA1922525@coredump.intra.peff.net","threadId":"64101","inReplyTo":"xmqqsegvtkgm.fsf@gitster.g","subject":"Re: Is Git Add Supposed to Work Like This (git 2.50)?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2025-09-09T21:01:38Z","receivedAt":"2025-09-09T21:01:40Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Sep 09, 2025 at 01:55:05PM -0700, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Oops, I think our mails just crossed. I don't think --ignore-errors does\n> > quite what you want, though:\n> >\n> >   $ touch foo\n> >   $ git add foo bar\n> >   fatal: pathspec 'bar' did not match any files\n> >   $ git add --ignore-errors foo bar\n> >   fatal: pathspec 'bar' did not match any files\n> >   $ git status --porcelain\n> >   ?? foo\n> \n> The option is described like so:\n> \n>     --[no-]ignore-errors  just skip files which cannot be added because of errors\n> \n> I think \"because of errors\" is meant handle a sequence more like this:\n> \n>     $ date >foo ; date >bar\n>     $ chmod a= foo\n>     $ git add --ignore-errors foo bar\n>     $ git diff --cached --name-only\n>     bar\n> \n\nYeah, I don't think --ignore-errors is misbehaving, and I read that doc.\nI just meant that it would not do the thing Jon is asking for. That is\nmore like --ignore-missing.\n\n-Peff\n"}]}