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

Re: bug:git-check-ignore exit status is wrong for negative patterns when -v option used

From
JFJeremy Faith <jeremy.faith@jci.com>
Date
Apr 29, 2021, 14:26 UTC
Message-ID
<CY4P132MB0088FC0DEE457E49EA21266F855F9@CY4P132MB0088.NAMP132.PROD.OUTLOOK.COM>
In-Reply-To
<3ea4e4c8-9723-4af6-5f07-9141c3001986@gmail.com>
on 28 April 2021 07:15 Bagas Sanjaya <bagasdotme@gmail.com> wrote:
 
Show 26 quoted lines
>On 27/04/21 23.30, Jeremy Faith wrote:
>> 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);
>I tried to apply this patch from the mbox, but it was corrupted, so I had to
>manually write the changes above. I tested that with your reproduction case and
>it worked as expected.
>But anyway, please send the proper patch and (preferentially) with the test
>consisting of the reproduction case.
>Thanks.

Sorry I just posted the output of 'git diff' previously but I cut off the first 2 lines by mistake. I'm not sure what is required as a test script.

diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index 3c652748d5..223cc6a1ef 100644
--- 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);
Previous: Bagas SanjayaNext: Junio C Hamano
Message 3 of 9 in “bug:git-check-ignore exit status is wrong for negative patterns when -v option used”
  1. Jeremy FaithApr 27, 2021
  2. Bagas SanjayaApr 28, 2021
  3. Jeremy FaithApr 29, 2021
  4. Junio C HamanoApr 28, 2021
  5. Jeremy FaithApr 29, 2021
  6. Junio C HamanoApr 30, 2021
  7. Jeremy FaithApr 30, 2021
  8. Elijah NewrenApr 30, 2021
  9. Junio C HamanoMay 3, 2021

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.