fix(cli): read .worktreeinclude and .gitignore as UTF-8 in worktree setup - #68798
Closed
solyanviktor-star wants to merge 1 commit into
Closed
fix(cli): read .worktreeinclude and .gitignore as UTF-8 in worktree setup#68798solyanviktor-star wants to merge 1 commit into
solyanviktor-star wants to merge 1 commit into
Conversation
…etup _setup_worktree read both files with the locale default encoding. On a cp1251/GBK Windows machine a UTF-8 include list either decodes to mojibake paths (non-ASCII entries silently not copied) or raises UnicodeDecodeError, which the enclosing handler logs at DEBUG and swallows — no include is copied at all, so the worktree starts without .env/keys and the agent breaks invisibly. A Notepad BOM likewise glues to the first include entry on every platform, and to the first .gitignore line, defeating the '.worktrees/' membership check and appending a duplicate entry on each run. Read both files with utf-8-sig + errors=replace, matching the canonical .env readers in hermes_cli/config.py (utf-8-sig because Notepad adds a BOM) and the UTF-8 append this same block already performs on .gitignore. Regression tests exercise the real cli._setup_worktree: the two BOM tests fail without the fix on any platform, the non-ASCII include test additionally reproduces the Windows locale failure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Merged via PR #71078 — your commit(s) were cherry-picked onto current main with your authorship preserved in git log (rebase merge). This PR was part of the class-wide close-out of bare |
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.
Summary
cli._setup_worktreereads.worktreeincludeand.gitignorewith the platform locale default encoding. Both are UTF-8 files (git treats path patterns as UTF-8; the same block already appends to.gitignorewithencoding="utf-8"), so on Windows this breaks in three ways:UnicodeDecodeErroroninclude_file.read_text(). The enclosingexcept Exceptionlogs at DEBUG and swallows it — no entry is copied at all, so the worktree starts without.env/keys and the agent breaks with no visible error.src.is_file()and are silently skipped (reproduced live on a cp1251 machine).\ufeffto the first entry (never copied), and a BOM'd.gitignoredefeats the.worktrees/membership check, appending a duplicate entry on each worktree launch.Fix
Read both files with
encoding="utf-8-sig", errors="replace", matching the canonical.envreaders inhermes_cli/config.py(utf-8-sig specifically because Notepad prepends a BOM) and the UTF-8 append this block already performs.Same class as the merged/endorsed encoding fixes #60895 / #62123 / #62617, previously unfixed in the worktree path.
Testing
New
TestWorktreeIncludeEncodingintests/cli/test_worktree_security.pyexercises the realcli._setup_worktree(same style as the existing security tests):test_bom_in_worktreeinclude_does_not_hide_first_entry— fails without the fix on any platformtest_bom_in_gitignore_does_not_duplicate_worktrees_entry— fails without the fix on any platformtest_non_ascii_worktreeinclude_entry_copied— reproduces the Windows locale failureAll three fail without the fix on Windows (verified by stashing the diff); full
tests/cli/test_worktree*suite otherwise unchanged (6 pre-existing failures in this Windows environment are present on clean main).ruffandscripts/check-windows-footguns.pyclean.Dedup: searched PRs/issues for worktreeinclude/gitignore encoding variants — existing
.worktreeincludePRs cover path traversal only; open Windows worktree PRs (#68252, #68391) touch quarantine/symlink semantics, not these reads.🤖 Generated with Claude Code