{"thread":{"id":"52292","subject":"git check-ignore returns 0 for negated masks","startedAt":"2019-11-19T14:01:47Z","lastAt":"2019-11-20T03:49:01Z","messageCount":2,"participants":["marat@seldon.slonopotamus.org","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"386515","messageId":"20191119140135.GA7389@seldon.slonopotamus.org","threadId":"52292","inReplyTo":null,"subject":"git check-ignore returns 0 for negated masks","fromName":"","fromEmail":"marat@seldon.slonopotamus.org","sentAt":"2019-11-19T14:01:35Z","receivedAt":"2019-11-19T14:01:47Z","isPatch":false,"sender":{"key":"marat@seldon.slonopotamus.org","avatar":null},"body":"Way to reproduce:\n\n$ git --version\ngit version 2.24.0\n$ mkdir /tmp/checkignore\n$ cd /tmp/checkignore\n$ git init\nInitialized empty Git repository in /tmp/checkignore/.git/\n$ echo '!*.txt' > .gitignore\n$ git check-ignore 1.txt\n1.txt\n$ echo $?\n0\n\nI believe this is a bug because it contradicts check-ignore documentation:\n\n  0 - One or more of the provided paths is ignored.\n  1 - None of the provided paths are ignored.\n\nThis bug isn't hard to fix, however:\n\n1. That causes several tests to fail because they test for exit code that I concider to be wrong.\n2. I'm not sure how to handle negated masks when check-ignore prints matching patterns.\n   Printing what pattern caused file to be *not* ignored seems useful,\n   but others may think that there's \"mask is printed iff the file is ignored\" rule.\n\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 5a4f92395f..d0711434e6 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -111,7 +111,7 @@ static int check_ignore(struct dir_struct *dir,\n                }\n                if (!quiet && (pattern || show_non_matching))\n                        output_pattern(pathspec.items[i].original, pattern);\n-               if (pattern)\n+               if (pattern && !(pattern->flags & PATTERN_FLAG_NEGATIVE))\n                        num_ignored++;\n        }\n        free(seen);\n"},{"id":"386606","messageId":"xmqqmucrcimx.fsf@gitster-ct.c.googlers.com","threadId":"52292","inReplyTo":"20191119140135.GA7389@seldon.slonopotamus.org","subject":"Re: git check-ignore returns 0 for negated masks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-11-20T03:48:54Z","receivedAt":"2019-11-20T03:49:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"marat@seldon.slonopotamus.org writes:\n\n> I believe this is a bug because it contradicts check-ignore documentation:\n>\n>   0 - One or more of the provided paths is ignored.\n>   1 - None of the provided paths are ignored.\n\nI think the doc was written with primarily positive entries in mind\n(it might even predate the introduction of the feature to allow\nnegative entries in the file), so it might need to be adjusted with\nsomething like s/be ignored/match the pattern/, perhaps?\n\n"}]}