Fix worktree cleanup for branches without upstreams#477
Open
cf-x wants to merge 1 commit into
Open
Conversation
cf-x
marked this pull request as ready for review
July 25, 2026 09:54
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
HEADinstead of@{push}git status,git rev-parse, orgit rev-listcannot verify cleanup safetyRoot cause
create_worktree()createswt/<name>branches without an upstream. The previousgit log @{push}..HEAD --onelinecheck therefore exited with status 128. Because the return code was ignored, its empty stdout was interpreted as zero commits, allowing a clean worktree with local-only commits to be force-removed along with its branch.A temporary worktree branch should not need an upstream for cleanup safety. The relevant baseline is the main worktree
HEAD: commits reachable only from the temporary worktree must prevent removal unlessdiscard_changes=trueis explicit.Validation
python -m pytest -q(28 passed, 48 subtests passed)python -m py_compile s18_worktree_isolation/code.py s19_mcp_plugin/code.py s20_comprehensive/code.py tests/test_worktree_cleanup.pygit diff --checkAI assistance
Codex assisted with reproducing the issue, implementing the fix, and running the tests. I reviewed the code and stand behind this change.
Fixes #476