All of lore.kernel.org
 help / color / mirror / Atom feed
From: marat@seldon.slonopotamus.org
To: git@vger.kernel.org
Subject: git check-ignore returns 0 for negated masks
Date: Tue, 19 Nov 2019 17:01:35 +0300	[thread overview]
Message-ID: <20191119140135.GA7389@seldon.slonopotamus.org> (raw)

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);

             reply	other threads:[~2019-11-19 14:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 14:01 marat [this message]
2019-11-20  3:48 ` git check-ignore returns 0 for negated masks Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191119140135.GA7389@seldon.slonopotamus.org \
    --to=marat@seldon.slonopotamus.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.