Repository navigation
fix(finishing-a-development-branch): clean up worktrees in the declar… - #2411
intertermux-code wants to merge 2 commits into
Conversation
…ed worktree directory using-git-worktrees honors a user-declared worktree directory ahead of its defaults, but finishing decided ownership by path only (`.worktrees/`/`worktrees/`), so worktrees it created in the declared directory were never cleaned up. The ownership rule now also covers the declared directory — the same preference using-git-worktrees reads. Fixes obra#2397.
ada-sen
left a comment
There was a problem hiding this comment.
Reproduced the bug and the fix mechanically (not through an agent session): built a scratch repo, created a worktree in a custom "declared" directory (not .worktrees//worktrees/), merged the branch locally, then walked Step 6's ownership check.
- Base (
main) text: the worktree is left behind — confirmed. Path-only ownership check (.worktrees//worktrees/) misses anything created in a declared directory, exactly as #2397 describes. - This PR's text: the widened condition correctly classifies that worktree as owned;
git worktree remove+worktree prunecleans it up, and the branch becomes deletable. Verified for the Merge Locally path; Discard shares the same Step 6 logic so it carries over. Options 2/3 are untouched (Step 6 still only runs for Option 1 and confirmed discards), so "keep" behavior is unaffected. - Git's own safety net still holds regardless of directory: a worktree with uncommitted/untracked files still gets
contains modified or untracked filesand the existing ask-before---forceflow, unforced by this change. - A worktree outside
.worktrees/,worktrees/, and the declared dir (e.g. one another tool manages) is correctly left alone.
One thing to consider before merging: the widened rule still infers ownership purely from location. .worktrees//worktrees/ are Superpowers-specific conventions unlikely to pre-exist; a declared directory is much more likely to already be where a user keeps their own worktrees (that's often exactly why they declared it). If a host-created, fully-committed worktree happens to live inside that same declared directory, this text would now tell the agent to remove it too — nothing in Step 6 distinguishes "we created this one" from "this one happens to share a directory we were told to use." Might be worth a line addressing that (or narrowing to "worktrees Superpowers itself created this session," if that's trackable) — skills/finishing-a-development-branch/SKILL.md:169-172 and the mirrored rationalization at :221.
Small nit: the diff appends a trailing blank line after the last table row (end of file) — cosmetic, not blocking.
Two process things worth flagging:
- Base branch: this targets
main, but the PR template says PRs must targetdev(mainis release-only), and recent merges (#2388, #2361, etc.) all land ondev. Givenmain/devare identical on this file right now, a retarget should be a clean no-op — but it'll need doing before this can merge the normal way. - Template sections: the PR body skips the "Who is submitting this PR?", "Existing PRs" checklist, and Evaluation/Rigor sections entirely. This is a behavior-shaping skill-text change (the linked issue #2397 even says as much: "This is a skill-text change, so it needs the usual eval evidence"), so it'd help to fill in the harness/model info and describe what testing was done before/after the change, per the template.
On overlap: #2294 and #2208 both edit the same paragraph this PR touches (adding SDD-workspace/uncommitted-file checks ahead of the git worktree remove call), so all three will conflict with each other on merge — not a duplicate (different concern: cleanup scope here vs. cleanup safety there), but whichever lands first will need the others rebased.
Net: the core fix is small, targeted, and matches the linked issue and my repro. Main blockers before merge are process (base branch + template) rather than correctness; the ownership-scope edge case above is worth a look but isn't disqualifying.
The declared worktree directory is a weaker ownership signal than the defaults -- a host may already keep their own worktrees there. The rule now applies only to the worktree this session checked out; a pre-existing host worktree in the declared directory belongs to the host. Also drop the trailing blank line at end of file.
|
Thanks for the thorough review — all addressed:
New head is 522da46 (retarget is a clean no-op, |
|
Correction to my previous comment: the base-branch retarget did not go through — the PR still targets |
|
@ada-sen — quick favor: could you retarget this PR's base from |
|
|
Just a friendly check-in on this one — all four review asks from ada-sen are addressed and the base is retargeted to dev. Let me know if there's anything else you'd like changed. |
using-git-worktreeshonors a user-declared worktree directory ahead of its defaults, butfinishing-a-development-branchdecided cleanup ownership by path alone (.worktrees//worktrees/). A worktree created in the declared directory was treated as host-owned and never cleaned up — one leftover per finished branch (see #2151, #1985, #666).The ownership rule now also covers the declared directory: the same preference
using-git-worktreesreads from the instructions file.Fixes #2397.
Who is submitting this PR?
What problem are you trying to solve?
finishing-a-development-branchStep 6 inferred worktree ownership purely from the path (.worktrees//worktrees/). Anyone who declares a custom worktree directory in their instructions — exactly whatusing-git-worktreesencourages — ended up with the finished worktree left behind on disk after every merge, one orphan per branch. Reported in #2397.What does this PR change?
Two things, same paragraph: (1) Step 6's ownership check now also treats the declared worktree directory as Superpowers-owned, so
git worktree remove+prunecleans it up; (2) a guard sentence narrows it to the worktree this session checked out — a pre-existing host worktree in the declared directory still belongs to the host. Trailing blank line at EOF removed.Is this change appropriate for the core library?
Yes.
finishing-a-development-branchand the declared-directory preference inusing-git-worktreesare both core, general-purpose workflow behavior — useful to anyone finishing branches from custom worktree directories, regardless of project or stack. No third-party integration, no domain-specific content.What alternatives did you consider?
WORKTREE_PATHcaptured in Step 2); per review feedback, a guard sentence covers the residual edge case instead.Does this PR contain multiple unrelated changes?
No. One concern (cleanup scope for the declared directory) in one file; the trailing-newline fix rides along in the same commit.
Existing PRs
:in description breaks f… #2410, fix(using-superpowers): correct stale Hermes tool mapping #2412 (same author's adjacent superpowers fixes, different skills)Environment tested
Evaluation
maintext): worktree left behind — confirmed. After (this PR's text): worktree correctly classified as owned;git worktree remove+worktree prunecleaned it up; branch deletable. Also verified: Discard shares the same Step 6 logic; Options 2/3 untouched; git's uncommitted-file safety net (contains modified or untracked files+ ask-before---force) unchanged; a worktree outside all known dirs still left alone.Rigor
superpowers:writing-skillsadversarial pressure testing — not run; the change is a small conditional widening plus one guard sentence, verified by direct mechanical reproduction instead.Human review