Skip to content

fix(sessions): decode git worktree paths as UTF-8 - #1580

Open
vexi1es wants to merge 1 commit into
anthropics:mainfrom
vexi1es:fix/worktree-paths-utf8
Open

vexi1es wants to merge 1 commit into
anthropics:mainfrom
vexi1es:fix/worktree-paths-utf8

Conversation

@vexi1es

@vexi1es vexi1es commented Nov 26, 2026

Copy link
Copy Markdown

Fixes #1579.

_get_worktree_paths ran git worktree list --porcelain with text=True, which decodes the output with the locale encoding. Git writes these paths as UTF-8 regardless of the locale, so on Windows (ANSI code page) a non-ASCII worktree path came back as mojibake and its sessions were not found; when a byte was undefined in the code page the decode failed in subprocess's reader thread, stdout came back empty, and list_sessions() lost the sessions of every worktree. The issue has a script that shows both on a cp1251 machine.

Change

Decode the output as UTF-8 (encoding="utf-8", errors="replace") instead of using the locale default. errors="replace" keeps one undecodable path from discarding the others.

Test

test_non_ascii_worktree_path_is_decoded_as_utf8 replaces subprocess.run with a fake that decodes git's UTF-8 bytes the way subprocess would: with the requested encoding, or cp1252 when none is given. It fails on main on every platform and passes with the change.

Verification

Windows 11, Python 3.10.6, system code page cp1251:

  • python -m pytest tests/: 1740 passed, 22 skipped
  • python -m ruff check src/ tests/ and ruff format --check: clean
  • python -m mypy src/: no issues
  • The reproduction script from the issue returns 3 of 3 sessions for both the сессия and Иван worktree names (1 or 2 of 3 before).

Not run: the e2e tests and other platforms.

#1225 proposed the same decoding fix earlier and was closed by its author without review.

git prints worktree paths as UTF-8 whatever the locale is, but the output was decoded with the locale encoding. On Windows that is an ANSI code page, so list_sessions() silently dropped the sessions of worktrees with non-ASCII paths, and of every worktree when a byte was undefined in the code page.

Fixes anthropics#1579

This branch has not been deployed

No deployments
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.

list_sessions() drops git worktree sessions on Windows when a worktree path is not ASCII

1 participant