{"thread":{"id":"47805","subject":"[PATCH] check-ignore: fix mix of directories and other file types","startedAt":"2018-02-10T12:38:42Z","lastAt":"2018-02-10T12:38:42Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"338987","messageId":"a6cf7660-8c80-c588-0cb7-88d507e56b06@web.de","threadId":"47805","inReplyTo":null,"subject":"[PATCH] check-ignore: fix mix of directories and other file types","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2018-02-10T12:38:29Z","receivedAt":"2018-02-10T12:38:42Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"In check_ignore(), the first pathspec item determines the dtype for any\nsubsequent ones.  That means that a pathspec matching a regular file can\nprevent following pathspecs from matching directories, which makes no\nsense.  Fix that by determining the dtype for each pathspec separately,\nby passing the value DT_UNKNOWN to last_exclude_matching() each time.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/check-ignore.c |  3 ++-\n t/t0008-ignores.sh     | 20 ++++++++++++++++++++\n 2 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 3e280b9c7a..ec9a959e08 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -72,7 +72,7 @@ static int check_ignore(struct dir_struct *dir,\n {\n \tconst char *full_path;\n \tchar *seen;\n-\tint num_ignored = 0, dtype = DT_UNKNOWN, i;\n+\tint num_ignored = 0, i;\n \tstruct exclude *exclude;\n \tstruct pathspec pathspec;\n \n@@ -104,6 +104,7 @@ static int check_ignore(struct dir_struct *dir,\n \t\tfull_path = pathspec.items[i].match;\n \t\texclude = NULL;\n \t\tif (!seen[i]) {\n+\t\t\tint dtype = DT_UNKNOWN;\n \t\t\texclude = last_exclude_matching(dir, &the_index,\n \t\t\t\t\t\t\tfull_path, &dtype);\n \t\t}\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex d27f438bf4..54a4703ef1 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -775,6 +775,26 @@ test_expect_success PIPE 'streaming support for --stdin' '\n \techo \"$response\" | grep \"^::\ttwo\"\n '\n \n+test_expect_success 'existing file and directory' '\n+\ttest_when_finished \"rm one\" &&\n+\ttest_when_finished \"rmdir top-level-dir\" &&\n+\t>one &&\n+\tmkdir top-level-dir &&\n+\tgit check-ignore one top-level-dir >actual &&\n+\tgrep one actual &&\n+\tgrep top-level-dir actual\n+'\n+\n+test_expect_success 'existing directory and file' '\n+\ttest_when_finished \"rm one\" &&\n+\ttest_when_finished \"rmdir top-level-dir\" &&\n+\t>one &&\n+\tmkdir top-level-dir &&\n+\tgit check-ignore top-level-dir one >actual &&\n+\tgrep one actual &&\n+\tgrep top-level-dir actual\n+'\n+\n ############################################################################\n #\n # test whitespace handling\n-- \n2.16.1\n"}]}