{"thread":{"id":"22074","subject":"suppress fatal pathspec errors from \"git add\"?","startedAt":"2009-12-31T21:24:59Z","lastAt":"2010-01-03T09:44:02Z","messageCount":6,"participants":["aaron smith","Jeff King","Junio C Hamano","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"130633","messageId":"d7ac1a680912311324i85b7a5anadaf2ac13f215873@mail.gmail.com","threadId":"22074","inReplyTo":null,"subject":"suppress fatal pathspec errors from \"git add\"?","fromName":"aaron smith","fromEmail":"beingthexemplarylists@gmail.com","sentAt":"2009-12-31T21:24:59Z","receivedAt":"2009-12-31T21:24:59Z","isPatch":false,"sender":{"key":"beingthexemplarylists@gmail.com","avatar":null},"body":"I'm looking through the add documentation, I don't see a way to\nsuppress fatal pathspec errors? For example, if I'm adding 5 files,\nbut one of them is mis-spelled, can I have git just supress the errors\nand add the other four?\nthanks much!\n"},{"id":"130722","messageId":"20100103074058.GB23031@sigill.intra.peff.net","threadId":"22074","inReplyTo":"d7ac1a680912311324i85b7a5anadaf2ac13f215873@mail.gmail.com","subject":"Re: suppress fatal pathspec errors from \"git add\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-01-03T07:40:59Z","receivedAt":"2010-01-03T07:40:59Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:\n\n> I'm looking through the add documentation, I don't see a way to\n> suppress fatal pathspec errors? For example, if I'm adding 5 files,\n> but one of them is mis-spelled, can I have git just supress the errors\n> and add the other four?\n\nHmm. I would have thought \"git add --ignore-errors\" would do what you\nwant, but it only ignores errors in reading the file. If we can't stat\nit, we will always die. IMHO that is an oversight in how\n\"--ignore-errors\" works (why should this one particular error be treated\nas fatal, when others are not?).\n\nHowever, I have to wonder what your workflow is to really want this. If\nyou do:\n\n  $ ls\n  foo bar baz\n  $ git add foo bar bz\n  fatal: pathspec 'bz' did not match any files\n\nThen presumably your next command would be:\n\n  $ git add foo bar baz\n\nUsing ignore-errors (if it worked), you would probably do:\n\n  $ git add baz\n\nLess typing, I suppose, but presumably you are using a shell that\nlets you just go back and edit the previous command line. I could see it\nif your workflow were something like \"in a script, add these N files if\nthey exist, but it is not an error if they don't\". But I still don't\nthink you would want to ignore all errors; you would want to do\nsomething like:\n\n  $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)\n\ninstead. Am I missing something?\n\n-Peff\n"},{"id":"130723","messageId":"d7ac1a681001030000n431d420ajb9b4733ad83ddecd@mail.gmail.com","threadId":"22074","inReplyTo":"20100103074058.GB23031@sigill.intra.peff.net","subject":"Re: suppress fatal pathspec errors from \"git add\"?","fromName":"aaron smith","fromEmail":"beingthexemplarylists@gmail.com","sentAt":"2010-01-03T08:00:30Z","receivedAt":"2010-01-03T08:00:30Z","isPatch":false,"sender":{"key":"beingthexemplarylists@gmail.com","avatar":null},"body":"Hey Jeff, thanks for the reply.\n\nYeah you hit it right on the head, it would be useful to suppress the\nerrors if you're running a script to add the files. I can certainly\nuse that snippet u provided - thanks. It would even be useful in git\nif you could suppress the errors, or maybe have a switch to list out\nthe files that failed, but add the ones that pass.. like \"git add\n--ignore-errors --list-failures\" something like that. Anyway, thanks\nfor the input.\n\n\n\nOn Sat, Jan 2, 2010 at 11:40 PM, Jeff King <peff@peff.net> wrote:\n> On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:\n>\n>> I'm looking through the add documentation, I don't see a way to\n>> suppress fatal pathspec errors? For example, if I'm adding 5 files,\n>> but one of them is mis-spelled, can I have git just supress the errors\n>> and add the other four?\n>\n> Hmm. I would have thought \"git add --ignore-errors\" would do what you\n> want, but it only ignores errors in reading the file. If we can't stat\n> it, we will always die. IMHO that is an oversight in how\n> \"--ignore-errors\" works (why should this one particular error be treated\n> as fatal, when others are not?).\n>\n> However, I have to wonder what your workflow is to really want this. If\n> you do:\n>\n>  $ ls\n>  foo bar baz\n>  $ git add foo bar bz\n>  fatal: pathspec 'bz' did not match any files\n>\n> Then presumably your next command would be:\n>\n>  $ git add foo bar baz\n>\n> Using ignore-errors (if it worked), you would probably do:\n>\n>  $ git add baz\n>\n> Less typing, I suppose, but presumably you are using a shell that\n> lets you just go back and edit the previous command line. I could see it\n> if your workflow were something like \"in a script, add these N files if\n> they exist, but it is not an error if they don't\". But I still don't\n> think you would want to ignore all errors; you would want to do\n> something like:\n>\n>  $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)\n>\n> instead. Am I missing something?\n>\n> -Peff\n>\n"},{"id":"130724","messageId":"7vk4vz38v0.fsf@alter.siamese.dyndns.org","threadId":"22074","inReplyTo":"20100103074058.GB23031@sigill.intra.peff.net","subject":"Re: suppress fatal pathspec errors from \"git add\"?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-03T08:12:19Z","receivedAt":"2010-01-03T08:12:19Z","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> ... I could see it\n> if your workflow were something like \"in a script, add these N files if\n> they exist, but it is not an error if they don't\". But I still don't\n> think you would want to ignore all errors; you would want to do\n> something like:\n>\n>   $ git add $(for i in foo bar baz; do test -e $i && echo $i; done)\n>\n> instead. Am I missing something?\n\nIf your primary activity that happens in the work tree were:\n\n\twhile :\n        do\n        \tfile=$(date +\"random-%H%M%S\")\n                >\"$file\"\n                rm -f \"$file\"\n\tdone\n\nand your add were done in\n\n\twhile sleep 3600\n        do\n\t\tgit add $(for i in *; do test -e $i && echo $i; done)\n                git commit -m \"hourly snapshot\"\n\tdone\n\ntotally asynchronously without coordinating with what the primary activity\nis doing, your \"test -e && echo\" can race with a concurrent \"rm\".\n\nEven though I think it is an insane use pattern that we shouldn't bother\nto bend too much backwards to support it, --ignore-errors were added\nprimarily for a similar use case (i.e. by the time we try to read it, it\nis either gone or it cannot be read by the user who runs \"git add\"), so in\nthat sense it _might_ make sense to ignore all errors with the option.  If\nwe choose to go in that direction, it would also make tons of sense to\nupdate the documentation of the option to caution more strongly that its\nuse is a sign of insanity and is discouraged at the same time.\n"},{"id":"130725","messageId":"20100103082804.GA23748@sigill.intra.peff.net","threadId":"22074","inReplyTo":"7vk4vz38v0.fsf@alter.siamese.dyndns.org","subject":"Re: suppress fatal pathspec errors from \"git add\"?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-01-03T08:28:05Z","receivedAt":"2010-01-03T08:28:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 03, 2010 at 12:12:19AM -0800, Junio C Hamano wrote:\n\n> If your primary activity that happens in the work tree were:\n> \n> \twhile :\n>         do\n>         \tfile=$(date +\"random-%H%M%S\")\n>                 >\"$file\"\n>                 rm -f \"$file\"\n> \tdone\n> \n> and your add were done in\n> \n> \twhile sleep 3600\n>         do\n> \t\tgit add $(for i in *; do test -e $i && echo $i; done)\n>                 git commit -m \"hourly snapshot\"\n> \tdone\n> \n> totally asynchronously without coordinating with what the primary activity\n> is doing, your \"test -e && echo\" can race with a concurrent \"rm\".\n\nOf course. But in such a situation, you are almost certainly better off\ndoing \"git add -A\". The external loop is really only useful if you want\nto add a subset of the files that may or may not exist for some reason.\nWhich is getting pretty specific and crazy.\n\nI haven't checked to see whether \"add -A\" has a race in discovering\nfiles versus actually adding them (I suppose there has to be one...even\nif we open() immediately and use fstat() and friends for everything\nelse, there still must be a race between getting the name from readdir()\nand calling open()).\n\nAnd I can see that as a potentially useful workflow: you are doing\nregular snapshots of a set of files which are being changed by an\noutside force. You care about errors, but not files disappearing between\nreaddir() and stat(). The \"find\" command has an \"--ignore-readdir-race\"\noption, which is what you would want.\n\nBut that is not \"--ignore-errors should also ignore missing files\". It\nis \"I want to ignore missing files but not other errors\".\n\n> Even though I think it is an insane use pattern that we shouldn't bother\n> to bend too much backwards to support it, --ignore-errors were added\n> primarily for a similar use case (i.e. by the time we try to read it, it\n> is either gone or it cannot be read by the user who runs \"git add\"), so in\n> that sense it _might_ make sense to ignore all errors with the option.  If\n> we choose to go in that direction, it would also make tons of sense to\n> update the documentation of the option to caution more strongly that its\n> use is a sign of insanity and is discouraged at the same time.\n\nI tracked down the original thread and it looks like the motivation was\nto handle repositories with a mixed set of readable and inaccessible\n(due to permissions) files:\n\n http://article.gmane.org/gmane.comp.version-control.git/75676\n\nSo I think it's not _totally_ insane there. You would do \"git add\n--ignore-errors .\" instead of having to manually write the shell loop of\naccessible items (though personally, I think I would just write the\nshell loop in that situation).\n\nThat's just my two cents on the matter. I'm not personally planning on\nwriting patches for either case.\n\n-Peff\n"},{"id":"130727","messageId":"m33a2ncyj2.fsf@localhost.localdomain","threadId":"22074","inReplyTo":"20100103074058.GB23031@sigill.intra.peff.net","subject":"Re: suppress fatal pathspec errors from \"git add\"?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-01-03T09:44:02Z","receivedAt":"2010-01-03T09:44:02Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Thu, Dec 31, 2009 at 01:24:59PM -0800, aaron smith wrote:\n> \n> > I'm looking through the add documentation, I don't see a way to\n> > suppress fatal pathspec errors? For example, if I'm adding 5 files,\n> > but one of them is mis-spelled, can I have git just supress the errors\n> > and add the other four?\n> \n> Hmm. I would have thought \"git add --ignore-errors\" would do what you\n> want, but it only ignores errors in reading the file. If we can't stat\n> it, we will always die. IMHO that is an oversight in how\n> \"--ignore-errors\" works (why should this one particular error be treated\n> as fatal, when others are not?).\n\nI have thought that this is task for --ignore-missing / --missing-ok\noption, but this option(s) does not apply to git-add / git-rm; the former\nis from git-write-index, the latter form from git-write-tree.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}