Repository navigation
fix(repo): unquote git check-ignore paths in Repo.ignored - #2298
Merged
Byron merged 1 commit intoOct 21, 2026
Merged
Conversation
`Repo.ignored` runs `git check-ignore -- <paths>` and recovered the
matched paths from stdout with
`.replace("\\\\", "\\").replace('"', "").split("\n")`. git C-quotes a
path that contains a non-ASCII byte (with the default `core.quotePath`),
a double quote, a backslash or a control character, and that replacement
does not reverse the quoting. With `*.env` in `.gitignore`:
- `données.env` came back as `donn\303\251es.env`
- `q"uote.env` came back as `q\uote.env`
- `tab<TAB>.env` came back as `tab\t.env`
- a name containing a line feed came back with a literal `\n`
A caller that compares the result with the paths it passed in, for
example to leave ignored files out of a commit, an upload or an archive,
therefore treats those ignored files as not ignored.
Read stdout as bytes and unquote each quoted line with
`git.diff._unquote_path`, which already reverses git's C-quoting for
patch headers. Splitting at line feeds stays safe because git always
quotes a path that contains one. `git check-ignore -z` would avoid the
quoting, but git accepts `-z` only together with `--stdin`. Paths git
does not quote are returned unchanged.
Adds `test_ignored_items_reported_verbatim` to `test/test_repo.py`; it
fails before this change and passes after. `ruff check`,
`ruff format --check` and `mypy` pass. The full pytest suite run locally
fails the same 83 tests with and without this change; those failures
come from fixture commits missing in the local clone, not from this
change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
repo.ignoredrangit check-ignore -- <paths>and undid git's c-quoting with two string replaces, which does not reverse it: with*.envignored,données.envcame back asdonn\303\251es.env,q"uote.envasq\uote.envandtab<TAB>.envastab\t.env, so a caller that matches the result against its own paths, for example to keep ignored files out of a commit or an upload, treats those files as not ignored. read stdout as bytes and unquote quoted lines with the existing_unquote_pathfromgit/diff.py; splitting at line feeds stays safe because git quotes any path containing one, and-zis not usable here since git accepts it only with--stdin. the new test intest/test_repo.pyfails before the change and passes after.