{"thread":{"id":"66690","subject":"[BUG] check-ignore matches trailing-slash paths against CRLF blank lines","startedAt":"2026-10-28T12:49:50Z","lastAt":"2026-11-21T09:45:51Z","messageCount":4,"participants":["Mike Beaton","Aniket Gupta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"556658","messageId":"CAHzAAWSi9D1mRL=A5-9GxzqQwo9jJ=45Hmxj3hVAF=8wkNZLmg@mail.gmail.com","threadId":"66690","inReplyTo":null,"subject":"[BUG] check-ignore matches trailing-slash paths against CRLF blank lines","fromName":"Mike Beaton","fromEmail":"mjsbeaton@gmail.com","sentAt":"2026-10-28T12:49:50Z","receivedAt":"2026-10-28T12:49:50Z","isPatch":false,"sender":{"key":"mjsbeaton@gmail.com","avatar":null},"body":"## Summary\n\nWith a .gitignore containing a single blank CRLF line, `git check-ignore -v`\nreports paths ending in `/` as ignored by an empty pattern. Replacing that\nblank line with an LF-only blank line removes the match.\n\nThis occurs with both ordinary names and dot-prefixed names. In the tests\nbelow, real files inside those directories remain visible to `git status`\nand eligible for `git add`. The observed issue is therefore an incorrect\nignore result for the trailing-slash path spelling, rather than demonstrated\nloss of files from normal status or staging operations.\n\n## Versions and environment\n\nReproduced on Linux using Git 2.56.0 built from the official source tarball,\nand also using Git 2.51.1.\n\nThe 2.56.0 build used:\n\n```sh\nmake -j8 NO_RUST=YesPlease NO_GETTEXT=YesPlease NO_TCLTK=YesPlease \\\n    NO_CURL=YesPlease NO_EXPAT=YesPlease git\n```\n\nThe 2.56.0 tests disabled system and global Git configuration using\n`GIT_CONFIG_NOSYSTEM=1` and `GIT_CONFIG_GLOBAL=/dev/null`.\n\nOriginally observed independently in a WSL working tree under /mnt/c.\n\n## Minimal reproduction\n\nRun in a shell with the Git executable to be tested on PATH:\n\n```sh\nrepro_dir=$(mktemp -d)\ncd \"$repro_dir\" || exit 1\nexport GIT_CONFIG_NOSYSTEM=1\nexport GIT_CONFIG_GLOBAL=/dev/null\n\ngit --version\ngit init -q --template=\n\n# Exactly one blank CRLF line; no ignore patterns.\nprintf '\\r\\n' > .gitignore\n\ngit check-ignore -v foo/ .foo/\nprintf 'exit status: %s\\n' \"$?\"\n\n# Same paths without trailing slashes.\ngit check-ignore -v foo .foo\nprintf 'exit status: %s\\n' \"$?\"\n\n# Replace CRLF with LF and repeat the first check.\nprintf '\\n' > .gitignore\ngit check-ignore -v foo/ .foo/\nprintf 'exit status: %s\\n' \"$?\"\n```\n\n## Actual result\n\nWith CRLF, the trailing-slash check reports the following (there is a tab\nbetween the final colon and each pathname):\n\n```text\n.gitignore:1:    foo/\n.gitignore:1:    .foo/\nexit status: 0\n```\n\nWithout trailing slashes, it prints no matching patterns and returns 1.\nAfter changing the blank line to LF, the trailing-slash check also prints no\nmatching patterns and returns 1.\n\nThe behaviour also reproduces when `foo` and `.foo` are existing directories\ncontaining files.\n\n## Expected result\n\nNeither path should match a blank line, regardless of the line-ending style\nor whether the pathname has a trailing slash. Both checks should print no\nmatches and return 1.\n\nThe gitignore documentation states: \"A blank line matches no files, so it\ncan serve as a separator for readability.\"\n\nhttps://git-scm.com/docs/gitignore\n\n## Checks with actual files\n\nIn the same temporary repository:\n\n```sh\nprintf '\\r\\n' > .gitignore\nmkdir foo .foo\nprintf 'hello\\n' > foo/test.txt\nprintf 'hello\\n' > .foo/test.txt\n\ngit check-ignore -v foo/ .foo/ foo .foo foo/test.txt .foo/test.txt\ngit status --porcelain --untracked-files=all\ngit add --dry-run -- foo/test.txt .foo/test.txt\n```\n\nOnly `foo/` and `.foo/` receive the unexpected ignore matches.\n`git status` lists both test files as untracked, and `git add --dry-run`\nreports that both would be added.\n\n## Reporting references\n\nGit's reporting instructions direct bug reports to git@vger.kernel.org:\n\nhttps://git-scm.com/community\n\nThis report concerns upstream Git, as it reproduces on Linux with an\nupstream source build; it is not specific to Git for Windows.\n\n"},{"id":"557724","messageId":"20261106182945.1316297-1-aniketgupta3001@gmail.com","threadId":"66690","inReplyTo":"CAHzAAWSi9D1mRL=A5-9GxzqQwo9jJ=45Hmxj3hVAF=8wkNZLmg@mail.gmail.com","subject":"[PATCH] dir: do not turn blank ignore-file lines into patterns","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-06T18:29:45Z","receivedAt":"2026-11-06T18:29:45Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"A blank line in an ignore file matches nothing. But\nadd_patterns_from_buffer() only skips a line when it is completely\nempty. A line that holds just a carriage return i.e a blank line in a\nfile with CRLF line endings or just spaces, is not empty at that\npoint. Once the carriage return and the trailing spaces are removed,\nwhat is left is an empty pattern, which matches any path that ends in\na slash. \"git check-ignore -v foo/\" then names the blank line as the\npattern that ignores foo/. Skip the line when nothing is left of it\nafter trimming and add a test.\n\nReported-by: Mike Beaton <mjsbeaton@gmail.com>\nSigned-off-by: Aniket Gupta <aniketgupta3001@gmail.com>\n---\n dir.c              | 3 ++-\n t/t0008-ignores.sh | 7 +++++++\n 2 files changed, 9 insertions(+), 1 deletion(-)\n\ndiff --git a/dir.c b/dir.c\nindex d896e7be4b..5a8a28afef 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1249,7 +1249,8 @@ int add_patterns_from_buffer(char *buf, size_t size,\n \t\t\tif (entry != buf + i && entry[0] != '#') {\n \t\t\t\tbuf[i - (i && buf[i-1] == '\\r')] = 0;\n \t\t\t\ttrim_trailing_spaces(entry);\n-\t\t\t\tadd_pattern(entry, base, baselen, pl, lineno);\n+\t\t\t\tif (*entry)\n+\t\t\t\t\tadd_pattern(entry, base, baselen, pl, lineno);\n \t\t\t}\n \t\t\tlineno++;\n \t\t\tentry = buf + i + 1;\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex ed95faf327..199abbcdf3 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -875,6 +875,13 @@ EOF\n \ttest_must_be_empty err\n '\n \n+test_expect_success 'blank lines are not patterns' '\n+\tmkdir blank-dir &&\n+\tprintf \"\\r\\n   \\n   \\r\\n\" >blank-ignore &&\n+\ttest_expect_code 1 git -c core.excludesfile=blank-ignore check-ignore blank-dir/ >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_expect_success !MINGW 'quoting allows trailing whitespace' '\n \trm -rf whitespace &&\n \tmkdir whitespace &&\n-- \n2.43.0\n\n\n"},{"id":"558865","messageId":"20261119171942.85689-1-aniketgupta3001@gmail.com","threadId":"66690","inReplyTo":"20261106182945.1316297-1-aniketgupta3001@gmail.com","subject":"Re: [PATCH] dir: do not turn blank ignore-file lines into patterns","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-19T17:19:42Z","receivedAt":"2026-11-19T17:19:42Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"Friendly ping. Just wanted to make sure this does not get lost.\n\n"},{"id":"559023","messageId":"20261121094551.30133-1-aniketgupta3001@gmail.com","threadId":"66690","inReplyTo":"CAHzAAWQo89ox+S_jtPX9DOtzfr-+3uMbWHN+HXdi9Aw2q57+Ng@mail.gmail.com","subject":"Re: [PATCH] dir: do not turn blank ignore-file lines into patterns","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-21T09:45:51Z","receivedAt":"2026-11-21T09:45:51Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"> Do I need to do anything\n\nNope. It is still waiting for a review.\n\n"}]}