{"thread":{"id":"47847","subject":"\"git add\" with several pathspecS and one doesn't match","startedAt":"2018-02-14T18:31:38Z","lastAt":"2018-02-14T19:30:03Z","messageCount":2,"participants":["Goffredo Baroncelli","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"339311","messageId":"d5e4138e-d5d6-3a84-a222-8d0170a52ccb@gmail.com","threadId":"47847","inReplyTo":null,"subject":"\"git add\" with several pathspecS and one doesn't match","fromName":"Goffredo Baroncelli","fromEmail":"kreijack@gmail.com","sentAt":"2018-02-14T18:31:28Z","receivedAt":"2018-02-14T18:31:38Z","isPatch":false,"sender":{"key":"kreijack@gmail.com","avatar":null},"body":"Hi All,\n\nI am facing this issue: I am ADDing some file with several pathspec, and one of these fails. The results is that no file is added at all.\n\nSimple test case:\n\n$ git init .\n$ touch 123.txt\n$ git add \"*.txt\" \"*.doc\"\nfatal: pathspec '*.doc' did not match any files\n$ git status\n[...]\nUntracked files:\n  (use \"git add <file>...\" to include in what will be committed)\n\n\t123.txt\n[...]\n\n\nResults: no file is added\nExpected results: the files which match any pathspec should be added\n\nLooking at the code, git works properly:\n\nfrom builtins/add.c, near line 500\n[...]\n\t\tfor (i = 0; i < pathspec.nr; i++) {\n\t\t\tconst char *path = pathspec.items[i].match;\n\t\t\tif (pathspec.items[i].magic & PATHSPEC_EXCLUDE)\n\t\t\t\tcontinue;\n\t\t\tif (!seen[i] && path[0] &&\n\t\t\t    ((pathspec.items[i].magic &\n\t\t\t      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||\n\t\t\t     !file_exists(path))) {\n\t\t\t\tif (ignore_missing) {\n\t\t\t\t\tint dtype = DT_UNKNOWN;\n\t\t\t\t\tif (is_excluded(&dir, &the_index, path, &dtype))\n\t\t\t\t\t\tdir_add_ignored(&dir, &the_index,\n\t\t\t\t\t\t\t\tpath, pathspec.items[i].len);\n\t\t\t\t} else\n\t\t\t\t\tdie(_(\"pathspec '%s' did not match any files\"),\n\t\t\t\t\t    pathspec.items[i].original);\n\t\t\t}\n\t\t}\n\n\nIt seems that if any pathspec doesn't match, all add action fails. Which is the rationale of this choice ? I would expect that an error message would be printed, but the matched files would be added.\n\nMy use case is the following: I use \"git\" as backup system, and I do something like:\n$ git add paths/*.doc \n$ git add paths/*.pdf\n$ git commit -m \"bla bla\"\n\nI know that git is not the best method for that, however we have a lot of files which are moved between different directories, and git seems to handle this job quite nicely. \nUnfortunately the filesystem is quite slow and quite huge, so I would prefer to do a single \"git add\", in order to avoid to traverse all the filesystem more times. But this would not work because if one pathspce fails, it prevents all other pathspecs to success.\n\n\nPlease put me in CC because I am not subscribed.\n\n\nBR\nG.Baroncelli\n\n\n-- \ngpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>\nKey fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5\n"},{"id":"339390","messageId":"xmqqtvujmksv.fsf@gitster-ct.c.googlers.com","threadId":"47847","inReplyTo":"d5e4138e-d5d6-3a84-a222-8d0170a52ccb@gmail.com","subject":"Re: \"git add\" with several pathspecS and one doesn't match","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-14T19:29:52Z","receivedAt":"2018-02-14T19:30:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Goffredo Baroncelli <kreijack@gmail.com> writes:\n\n> I am facing this issue: I am ADDing some file with several\n> pathspec, and one of these fails. The results is that no file is\n> added at all.\n\nThis is a good example of a pretty conscious design decision to keep\noperations atomic/a-o-n when appropriate.\n\n"}]}