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

[PATCH] dir: do not turn blank ignore-file lines into patterns

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Nov 6, 2026, 18:29 UTC
Message-ID
<20261106182945.1316297-1-aniketgupta3001@gmail.com>
In-Reply-To
<CAHzAAWSi9D1mRL=A5-9GxzqQwo9jJ=45Hmxj3hVAF=8wkNZLmg@mail.gmail.com>

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 <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);
 			}
 			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
Previous: Mike BeatonNext: Aniket Gupta
Message 2 of 3 in “[BUG] check-ignore matches trailing-slash paths against CRLF blank lines”
  1. Mike BeatonOct 28, 2026
  2. dir: do not turn blank ignore-file lines into patternsAniket Gupta, Nov 6, 2026
  3. Aniket GuptaNov 19, 2026

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.