Git development
 help / color / mirror / Atom feed
From: "Matt Hunter" <m@lfurio.us>
To: "Aniket Gupta" <aniketgupta3001@gmail.com>, <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Mike Beaton" <mjsbeaton@gmail.com>,
	"Phillip Wood" <phillip.wood123@gmail.com>
Subject: Re: [PATCH] dir: do not turn blank ignore-file lines into patterns
Date: Sat, 28 Nov 2026 00:24:25 -0500	[thread overview]
Message-ID: <DN6LDMN4UVPP.ZUG3AO2YOIZG@lfurio.us> (raw)
In-Reply-To: <20261106182945.1316297-1-aniketgupta3001@gmail.com>

Hi Aniket, Mike

I've been looking into this patch as well, but have been slow to
respond, sorry.  Just a couple of thoughts below.

On Fri Nov 6, 2026 at 1:29 PM EST, Aniket Gupta wrote:
> A blank line in an ignore file matches nothing. But
> add_patterns_from_buffer() only skips a line when it is completely
> empty. A line that holds just a carriage return i.e a blank line in a
> file with CRLF line endings or just spaces, is not empty at that
> point. Once the carriage return and the trailing spaces are removed,
> what is left is an empty pattern, which matches any path that ends in
> a slash. "git check-ignore -v foo/" then names the blank line as the
> pattern that ignores foo/. Skip the line when nothing is left of it
> after trimming and add a test.

Given these two points from gitignore(5):

    - A blank line matches no files, so it can serve as a separator
      for readability.
    - Trailing spaces are ignored unless they are quoted with
      backslash ("`\`").

this definitely seems like a bug worth addressing.

Something that initially confused me while attempting to reproduce the
problem was that git-status and git-add behave correctly.  Even running
'git add some-directory/' with the trailing slash present, stages the
expected files.  I went back to the original bug report and saw that
these details were commented on.  It would be helpful to mention in the
commit log message if the problem is specific to check-ignore.

>
> Reported-by: Mike Beaton <mjsbeaton@gmail.com>
> Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
> ---
>  dir.c              | 3 ++-
>  t/t0008-ignores.sh | 7 +++++++
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/dir.c b/dir.c
> index d896e7be4b..5a8a28afef 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1249,7 +1249,8 @@ int add_patterns_from_buffer(char *buf, size_t size,
>  			if (entry != buf + i && entry[0] != '#') {
>  				buf[i - (i && buf[i-1] == '\r')] = 0;
>  				trim_trailing_spaces(entry);
> -				add_pattern(entry, base, baselen, pl, lineno);
> +				if (*entry)
> +					add_pattern(entry, base, baselen, pl, lineno);

This avoids adding a pattern which becomes empty after stripping a
carriage return and any spaces.  I wonder if it is also worth fixing up
the parsing responsible for interpreting such "whitespace only" patterns
to match ".*/"?  Either way, I think this patch is an improvement as-is.

>  			}
>  			lineno++;
>  			entry = buf + i + 1;
> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
> index ed95faf327..199abbcdf3 100755
> --- a/t/t0008-ignores.sh
> +++ b/t/t0008-ignores.sh
> @@ -875,6 +875,13 @@ EOF
>  	test_must_be_empty err
>  '
>  
> +test_expect_success 'blank lines are not patterns' '

Should this test description be more about the spelling of the
(inadvertently) ignored directory?  That might better explain the
specific check-ignore assertion that is made.

> +	mkdir blank-dir &&
> +	printf "\r\n   \n   \r\n" >blank-ignore &&
> +	test_expect_code 1 git -c core.excludesfile=blank-ignore check-ignore blank-dir/ >actual &&
> +	test_must_be_empty actual
> +'
> +
>  test_expect_success !MINGW 'quoting allows trailing whitespace' '
>  	rm -rf whitespace &&
>  	mkdir whitespace &&

  parent reply	other threads:[~2026-11-28  5:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 12:49 [BUG] check-ignore matches trailing-slash paths against CRLF blank lines Mike Beaton
2026-11-06 18:29 ` [PATCH] dir: do not turn blank ignore-file lines into patterns Aniket Gupta
2026-11-19 17:19   ` Aniket Gupta
     [not found]     ` <CAHzAAWQo89ox+S_jtPX9DOtzfr-+3uMbWHN+HXdi9Aw2q57+Ng@mail.gmail.com>
2026-11-21  9:45       ` Aniket Gupta
2026-11-27 16:21   ` Aniket Gupta
2026-11-28  5:24   ` Matt Hunter [this message]
2026-11-28  7:28     ` Aniket Gupta
2026-11-28 10:47     ` Aniket Gupta
2026-11-29  3:21       ` Junio C Hamano
2026-11-28  6:54   ` Junio C Hamano
2026-11-28  7:28     ` Aniket Gupta
2026-11-29  4:01       ` Junio C Hamano
2026-11-28  9:38   ` Matt Hunter
2026-11-28 10:12     ` Aniket Gupta
2026-11-29  6:00   ` [PATCH v2] dir: ignore CRLF-empty and space-only lines in pattern files Aniket Gupta
2026-11-29 11:14     ` Matt Hunter
2026-11-29 11:42       ` Aniket Gupta

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=DN6LDMN4UVPP.ZUG3AO2YOIZG@lfurio.us \
    --to=m@lfurio.us \
    --cc=aniketgupta3001@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mjsbeaton@gmail.com \
    --cc=phillip.wood123@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox