Repository navigation
Conversation
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
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.
Fixes #1579.
_get_worktree_pathsrangit worktree list --porcelainwithtext=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, andlist_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_utf8replacessubprocess.runwith 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 onmainon 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 skippedpython -m ruff check src/ tests/andruff format --check: cleanpython -m mypy src/: no issuesсессия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.