fix(worktree): reconcile detached-HEAD worktrees, run prune on clean, clamp zero timeout#6051
Merged
Merged
Conversation
… clamp zero timeout reconcile() previously dropped any worktree whose git worktree list --porcelain block lacked a branch line (detached HEAD), making such entries permanently invisible to list/clean. The porcelain parser now flushes on the worktree <path> line alone and assigns a sentinel branch_name that is provably not a valid git ref, so it can never collide with a real (including foreign, non-zeph) branch (#5936). zeph worktree clean now runs git worktree prune once after removing stale entries, per spec-063 FR-CLEANUP-04 (#5937). DefaultGitRunner now clamps git_timeout_secs=0 to a 1-second floor internally, so the invariant holds regardless of caller; the two ad hoc .max(1) call sites and the bypassable derived Default impl are removed (#5939).
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
Three related bug fixes in
crates/zeph-worktree, spec-governed byspecs/063-worktree-subsystem/spec.mdandsrs.md:WorktreeManager::reconcile()silently dropped detached-HEAD worktrees because thegit worktree list --porcelainparser only flushed a block when both aworktree <path>line and abranchline were present. Detached worktrees emitdetachedinstead ofbranch, so they became permanently invisible tozeph worktree list/zeph worktree clean. The parser now flushes wheneverworktree <path>is seen, and assigns a newDETACHED_BRANCH_SENTINEL("(detached HEAD)") asbranch_namewhen no branch line is present. The sentinel contains a space, whichgit check-ref-format --branchrejects, so it can never collide with a real branch name — including on a worktree foreign to zeph, sincereconcile()enumerates all worktrees in the repo, not just zeph-managed ones.zeph worktree cleannever calledgit worktree pruneafter removing stale entries, per spec-063 FR-CLEANUP-04. AddedWorktreeManager::prune()and wired it into the clean command after the removal loop.DefaultGitRunnerdid not clampgit_timeout_secs = 0itself; the clamp was duplicated ad hoc at two call sites, and the crate's derivedDefaultimpl bypassed both (zero-initializing theDurationfield). The clamp now lives inDefaultGitRunner::new()/with_timeout(), the ad hoc call-site clamps were removed, andDefaultis now a manual impl delegating tonew().A P3 follow-up issue will be filed separately for
bare-repo worktrees also falling through to the detached sentinel (mislabeling, not a spec violation — spec-063 doesn't cover bare worktrees) — that gap was found during review and intentionally deferred out of this PR's scope.Closes #5936
Closes #5937
Closes #5939
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins— 12828 passed, 0 failedRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --lockedcargo test --doc --workspace --features "desktop,ide,server,chat,pdf,scheduler"crates/zeph-worktree/tests/real_git_integration.rs(uses the realgitbinary, not a fake runner): prune clears a manually-removed worktree's leftover admin entry, full clean pipeline (reconcile+remove+prune), zero-timeout clamp against a real git invocation, and the sentinel's ref-name invalidity viagit check-ref-format.local/testing/playbooks/worktree.mdand.local/testing/coverage-status.mdupdated in the main repo