On Sun Nov 29, 2026 at 1:00 AM EST, Aniket Gupta wrote:
> add_patterns_from_buffer() skips an empty line which starts right at the > '\n', before it strips the '\r' or any trailing spaces. A two byte > "\r\n" line in a CRLF file, or a line that holds only spaces (with or > without the '\r') is not empty at that point. Stripping the '\r' and > calling trim_trailing_spaces() reduces it to an empty string, which is > then passed to add_pattern(). > > parse_path_pattern() turns that empty string into a 0 length pattern > with PATTERN_FLAG_NODIR. The directory walk checks a directory before it > appends the trailing slash. Thus, status and a plain add are not > affected. A path that ends in a slash is a different scenario. For eg,
s/path/path argument/ ? Outside of a user's spelling, a directory name would not actually contain a slash, right?
> with "git check-ignore foo/", the basename is empty and match_basename() > matches the 0 length pattern and "check-ignore -v" names that line as > the reason foo/ is ignored. > > Cone-mode sparse-checkout is affected as well. For such a line, > add_pattern_to_hashsets() sees a pattern shorter than 2 characters, > warns "unrecognized pattern: ''" and disables cone pattern matching. > > Skip calling add_pattern() when the trimmed line is empty. This follows > gitignore(5) which says that trailing spaces are ignored unless quoted > with backslash. A file name made of spaces can still be matched by > quoting the spaces, like before.
Perhaps drop the "like before", since "still be matched" suggests unchanged behavior.
> > Reported-by: Mike Beaton <mjsb…@gmail.com> > Signed-off-by: Aniket Gupta <anik…@gmail.com> > --- > Changes in v2: > > - Rewrite the log message without the word "blank" (Junio). > - Explain in the log message why status and add are not affected, > with check-ignore as the example (Matt), and mention that > cone-mode sparse-checkout warns on such lines (Junio). > - Rename the test and drop the mkdir (Matt). > - Keep the fix in add_patterns_from_buffer() instead of moving it > into match_basename() as I suggested to Matt. Cone mode warns > before any matching runs (Junio), so the line has to be skipped > here.
I think this is the better choice.
> Making match_basename() reject empty patterns can be a > separate change. > > @@ -875,6 +875,13 @@ EOF > test_must_be_empty err > ' > > +test_expect_success 'trailing-slash directory is not ignored by CRLF-empty or space-only lines' '
I debated suggesting to say "patterns" instead of "lines" here. But the word "lines" is used much more consistently throughout the patch (and doing so makes more sense). So never mind?
> + printf "\r\n \n \r\n" >empty-lines && > + test_expect_code 1 git -c core.excludesfile=empty-lines \ > + check-ignore dir/ >actual && > + test_must_be_empty actual
The updated test looks good.