git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git check-ignore returns 0 for negated masks

From
Mmarat@seldon.slonopotamus.org <marat@seldon.slonopotamus.org>
Date
Nov 19, 2019, 14:01 UTC
Message-ID
<20191119140135.GA7389@seldon.slonopotamus.org>
Way to reproduce:

$ git --version git version 2.24.0 $ mkdir /tmp/checkignore $ cd /tmp/checkignore $ git init Initialized empty Git repository in /tmp/checkignore/.git/ $ echo '!*.txt' > .gitignore $ git check-ignore 1.txt 1.txt $ echo $? 0

I believe this is a bug because it contradicts check-ignore documentation:
  0 - One or more of the provided paths is ignored.
  1 - None of the provided paths are ignored.
This bug isn't hard to fix, however:
1. That causes several tests to fail because they test for exit code that I concider to be wrong.
2. I'm not sure how to handle negated masks when check-ignore prints matching patterns.
   Printing what pattern caused file to be *not* ignored seems useful,
   but others may think that there's "mask is printed iff the file is ignored" rule.
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 5a4f92395f..d0711434e6 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -111,7 +111,7 @@ static int check_ignore(struct dir_struct *dir,
                }
                if (!quiet && (pattern || show_non_matching))
                        output_pattern(pathspec.items[i].original, pattern);
-               if (pattern)
+               if (pattern && !(pattern->flags & PATTERN_FLAG_NEGATIVE))
                        num_ignored++;
        }
        free(seen);
Next: Junio C Hamano
Message 1 of 2 in “git check-ignore returns 0 for negated masks”
  1. marat@seldon.slonopotamus.orgNov 19, 2019
  2. Junio C HamanoNov 20, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.