{"thread":{"id":"28077","subject":"git ls-files --error-unmatch weirdness","startedAt":"2011-08-12T13:24:36Z","lastAt":"2011-08-12T17:56:30Z","messageCount":3,"participants":["SZEDER Gábor","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"173399","messageId":"20110812132436.GA12147@goldbirke","threadId":"28077","inReplyTo":null,"subject":"git ls-files --error-unmatch weirdness","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-08-12T13:24:36Z","receivedAt":"2011-08-12T13:24:36Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nI was looking for untracked files when noticed this:\n\nrepo$ git init\nInitialized empty Git repository in /home/szeder/tmp/git/repo/.git/\nrepo (master)$ mkdir dir\nrepo (master)$ touch dir/file\nrepo (master)$ git add dir/file\nrepo (master)$ git commit -m 'first'\n[master (root-commit) 2c0990c] first\n 0 files changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 dir/file\nrepo (master)$ git ls-files --others --error-unmatch\nrepo/dir (master)$ echo $?\n0\nrepo (master)$ cd dir\nrepo/dir (master)$ git ls-files --others --error-unmatch\nerror: pathspec '' did not match any file(s) known to git.\nDid you forget to 'git add'?\nrepo/dir (master)$ echo $?\n1\n\nSo, the same 'git ls-files' command is OK when run at the top of the\nworktree, but errors out in a subdirectory.  What's going on?  Is this\na bug?  If not, why not?\n\n\nThanks,\nGábor\n"},{"id":"173401","messageId":"CACsJy8D0-SqSY0q2hJ0+w_NeT_s0Uza=Bi8-y37EKWE2VZhYeQ@mail.gmail.com","threadId":"28077","inReplyTo":"20110812132436.GA12147@goldbirke","subject":"Re: git ls-files --error-unmatch weirdness","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-08-12T14:17:33Z","receivedAt":"2011-08-12T14:17:33Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/8/12 SZEDER Gábor <szeder@ira.uka.de>:\n> So, the same 'git ls-files' command is OK when run at the top of the\n> worktree, but errors out in a subdirectory.  What's going on?  Is this\n> a bug?  If not, why not?\n\nreport_path_error() in ls-files.c is meant to check pathspecs given by\nuser. However when in a subdir, get_pathspec() automatically adds a\npathspec (that is prefix). This new pathspec confuses\nreport_path_error(). The following patch may help (possibly corrupted\nbecause I paste in gmail, but you get the idea)\n\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 0e98bff..e0611ac 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -545,7 +545,8 @@ int cmd_ls_files(int argc, const char **argv,\nconst char *cmd_prefix)\n \tmax_prefix_len = max_prefix ? strlen(max_prefix) : 0;\n\n \t/* Treat unmatching pathspec elements as errors */\n-\tif (pathspec && error_unmatch) {\n+\tif (pathspec && error_unmatch &&\n+\t    (!prefix || pathspec[1])) {\n \t\tint num;\n \t\tfor (num = 0; pathspec[num]; num++)\n \t\t\t;\n\n-- \nDuy\n"},{"id":"173411","messageId":"7vaabeo6nl.fsf@alter.siamese.dyndns.org","threadId":"28077","inReplyTo":"20110812132436.GA12147@goldbirke","subject":"Re: git ls-files --error-unmatch weirdness","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-08-12T17:56:30Z","receivedAt":"2011-08-12T17:56:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> repo (master)$ git ls-files --others --error-unmatch\n\nThe \"--error-unmatch\" is about reporting errors in pathspecs you gave from\nthe command line. The behaviour is undefined if you do not give any, like\nthe above command line.\n\nHaving said that, I wouldn't be surprised if it triggered when run from an\nempty subdirectory.\n"}]}