git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* bug:git-check-ignore exit status is wrong for negative patterns when -v option used
@ 2021-04-27 16:30 Jeremy Faith
  2021-04-28  6:15 ` Bagas Sanjaya
  2021-04-28  7:13 ` Junio C Hamano
  0 siblings, 2 replies; 9+ messages in thread
From: Jeremy Faith @ 2021-04-27 16:30 UTC (permalink / raw)
  To: git@vger.kernel.org

Hi,

git version 2.31.1.362.g311531c9de
git-check-ignore 
When a negative pattern is the last .gitignore match the -v option causes the exit status to be 0 rather than the expected 1.
e.g say .gitignore contains  one line: !hello
git check-ignore hello #outputs nothing
echo $?  #shows correct exit status=1 i.e None of the provided paths are ignored.
but
git check-ignore -v hello #output is next line
.gitignore:4:!hello	hello
echo $?  #shows wrong exit status=0 i.e. One or more of the provided paths is ignored

Following change seems to fix it for me
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -114,7 +114,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);

Regards,
Jeremy Faith

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-03  3:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 16:30 bug:git-check-ignore exit status is wrong for negative patterns when -v option used Jeremy Faith
2021-04-28  6:15 ` Bagas Sanjaya
2021-04-29 14:26   ` Jeremy Faith
2021-04-28  7:13 ` Junio C Hamano
2021-04-29 14:10   ` Jeremy Faith
2021-04-30  0:22     ` Junio C Hamano
2021-04-30  9:56       ` Jeremy Faith
2021-04-30 20:51         ` Elijah Newren
2021-05-03  3:09         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).