From: Aniket Gupta Date: Fri, 06 Nov 2026 18:29:45 GMT Subject: [PATCH] dir: do not turn blank ignore-file lines into patterns Message-ID: <20261106182945.1316297-1-aniketgupta3001@gmail.com> In-Reply-To: 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. Reported-by: Mike Beaton Signed-off-by: Aniket Gupta --- 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); } 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' ' + 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 && -- 2.43.0