Skip to content

fix(repo): handle Unicode in quoted untracked filenames - #2302

Open
BHARTIYAYASH wants to merge 1 commit into
gitpython-developers:mainfrom
BHARTIYAYASH:fix/untracked-unicode-quoted-paths
Open

BHARTIYAYASH wants to merge 1 commit into
gitpython-developers:mainfrom
BHARTIYAYASH:fix/untracked-unicode-quoted-paths

Conversation

@BHARTIYAYASH

@BHARTIYAYASH BHARTIYAYASH commented Oct 22, 2026 •

Copy link
Copy Markdown

Problem

With core.quotePath=false, Git can mix raw UTF-8 with C-style escapes in a quoted status path. Repo.untracked_files converts the entire quoted path to ASCII before decoding the escapes, so a valid filename such as café\x7f.txt raises UnicodeEncodeError. This also affects Repo.is_dirty(untracked_files=True).

The reproduction uses an actual temporary repository and Git's status output; DEL is permitted in Windows filenames, so it also runs on Windows.

Change

Reuse _unquote_path, which Repo.ignored already uses, and retain the existing string return type. The regression checks both core.quotePath=true and false, along with ordinary ASCII and Unicode paths.

Verification

  • The new regression failed before the implementation change.
  • Related filename tests: 4 passed, 1 skipped, 2 subtests passed.
  • Repository/diff modules: 151 passed, 3 skipped, 2 xfailed, 16 subtests passed; three other tests initially failed because this machine defaults to main. All three passed when rerun with a process-local init.defaultBranch=master setting.
  • Ruff lint and formatting, mypy on the changed source module, and git diff --check passed.
  • Additional core-suite run: 1,290 passed, 58 skipped, 8 xfailed, and 88 subtests passed. It stopped at three test_move_rejects_intermediate_symlink setup failures because Windows denied os.symlink with WinError 1314. All three failures were reproduced on unmodified upstream ccc48117; the complete core suite was not run to completion.

Prepared and submitted by OpenAI Codex, an AI agent operating through BHARTIYAYASH's account. Human review is pending.

With `core.quotePath=false`, Git can emit raw UTF-8 characters alongside
C-style escapes in a quoted status path. `Repo.untracked_files` forced
that path through ASCII before unquoting it, raising `UnicodeEncodeError`
for a filename such as `café\x7f.txt`.

Reuse the existing `_unquote_path` byte decoder, as `Repo.ignored` already
does. The regression uses real Git output with both `core.quotePath`
settings and also checks the `Repo.is_dirty` caller.

Validation: the regression failed before the change. Related filename
tests passed (4 passed, 1 skipped, 2 subtests passed), and Ruff lint,
formatting, and `git diff --check` passed.
@BHARTIYAYASH
BHARTIYAYASH marked this pull request as ready for review October 22, 2026 16:03
@Byron
Byron requested a balanced review from Copilot October 22, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow decoder change and targeted regression coverage leave no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR fixes Unicode filename handling in Repo.untracked_files when Git mixes raw UTF-8 with escaped characters, also addressing the affected Repo.is_dirty(untracked_files=True) call.

Changes:

  • Reuse _unquote_path instead of the ASCII-only decoding sequence while preserving string results.
  • Add regression coverage for both core.quotePath settings, mixed Unicode and escaped characters, and ordinary filenames.

Review by GitHub Copilot; tests were not independently run.

File Description
test/​test_repo.py Tests untracked filenames and dirty-state detection under both quoting settings.
git/​repo/​base.py Uses the existing path decoder to handle quoted Unicode filenames.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants