Skip to content

fix(team): read and write .git/info/exclude as UTF-8 - #237

Open
Dev-next-gen wants to merge 1 commit into
HKUDS:mainfrom
Dev-next-gen:fix/team-exclude-utf8
Open

Dev-next-gen wants to merge 1 commit into
HKUDS:mainfrom
Dev-next-gen:fix/team-exclude-utf8

Conversation

@Dev-next-gen

Copy link
Copy Markdown

Description

While looking at the recent fix that made the hooks loader read its config as UTF-8 (cdd2681), I noticed the same pattern in core/team/worktree.py. WorktreeManager installs and later removes its ignore block in the repository's .git/info/exclude using Path.read_text() / write_text() with no encoding, so the locale encoding is used. On a Windows machine with the default cp1252 locale, an existing user rule such as 数据/ makes read_text() raise UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d. ensure_base() doesn't catch it, so every isolated sub-agent run in core/harness/agents/control.py fails before its worktree is created.

This PR reads and writes the file as UTF-8 explicitly, like the hooks loader does now. On UTF-8 locales nothing changes.

Related Issues

None that I could find.

Changes Made

  • core/team/worktree.py: pass encoding="utf-8" to the two read_text() and two write_text() calls on .git/info/exclude.
  • tests/test_team_worktree.py: new test_team_exclude_keeps_non_ascii_user_rules. It puts a UTF-8 rule in .git/info/exclude, then runs an install/remove cycle and checks that the rule is still there, byte for byte.

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

Before and after results for the new test:

  • Windows, Python 3.12, cp1252. I didn't have pytest there, so I called the test functions directly. Before the fix it fails with UnicodeDecodeError ... byte 0x8d. After the fix, the new test and the existing exclude test both pass.
  • Linux, Python 3.14, pytest, with PYTHONUTF8=0 PYTHONCOERCECLOCALE=0 LC_ALL=C so the locale encoding is ASCII. Before the fix: 1 failed, 6 passed. After the fix: 7 passed, and 7 passed again under the normal UTF-8 locale.

The Windows job in python-ci should hit the same failure without the fix.

Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.

The team worktree manager rewrites the repository's .git/info/exclude
with Path.read_text()/write_text() and no encoding, so the locale
encoding is used. On Windows (cp1252) a user rule such as "数据/"
raises UnicodeDecodeError, which aborts ensure_base() and with it every
isolated sub-agent run. Use UTF-8 explicitly, as the hooks config
loader already does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant