bug(finish): a merged worktree stays on disk until a second call removes it #691

Open
opened 2026-10-03 15:41:17 +00:00 by hexajon · 0 comments
Owner

Problem

When I finish a branch that lives in a linked worktree, madt_finish merges the PR and leaves the worktree on disk. Removing it takes a second call, madt_worktrees action=remove. In a batch of 40 small changes across repos, that is 40 extra calls, and a skipped call leaves a stale worktree and branch behind.

Ask

After the merge lands, madt_finish removes the linked worktree that has the finished branch checked out, but only when the ADR 0029 proof holds:

  • git finds the worktree clean, and
  • the forge's API confirms that the commits of its branch are reachable from the forge's default branch.

A failed forge read, a dirty tree, or a missing proof leaves the worktree in place, and the result says why.

Decision records

  • ADR 0029 already classifies a clean worktree remove as machine-proof. This change uses the same proof and adds no new destructive path.
  • ADR 0019 says the foreign flow ends at madt_finish plus worktree cleanup with madt_worktrees action=remove. This change folds the cleanup into finish, so ADR 0019 needs a dated amendment to that sentence.

Cases

  • Merged now: the proof runs, and the worktree is removed.
  • Auto-merge scheduled (the forge merges when checks pass): nothing is merged yet, so the worktree stays, and the result says the merge is pending.
  • Merged with squash or rebase: the branch commits are not on the default branch, only their content. ADR 0029 lets prune use a content proof for that case, but its worktree row names commits only. Open question: does worktree removal accept the content proof too?

Acceptance

  • A finish from a clean linked worktree, merged with a merge commit, removes the worktree once the forge proof passes.
  • A finish whose merge is only scheduled leaves the worktree and says the merge is pending.
  • With the forge out of reach, the worktree stays, and the result says the proof failed.
  • A dirty worktree stays.

Depends on #666.

## Problem When I finish a branch that lives in a linked worktree, `madt_finish` merges the PR and leaves the worktree on disk. Removing it takes a second call, `madt_worktrees action=remove`. In a batch of 40 small changes across repos, that is 40 extra calls, and a skipped call leaves a stale worktree and branch behind. ## Ask After the merge lands, `madt_finish` removes the linked worktree that has the finished branch checked out, but only when the ADR 0029 proof holds: - git finds the worktree clean, and - the forge's API confirms that the commits of its branch are reachable from the forge's default branch. A failed forge read, a dirty tree, or a missing proof leaves the worktree in place, and the result says why. ## Decision records - ADR 0029 already classifies a clean worktree remove as machine-proof. This change uses the same proof and adds no new destructive path. - ADR 0019 says the foreign flow ends at `madt_finish` plus worktree cleanup with `madt_worktrees action=remove`. This change folds the cleanup into finish, so ADR 0019 needs a dated amendment to that sentence. ## Cases - Merged now: the proof runs, and the worktree is removed. - Auto-merge scheduled (the forge merges when checks pass): nothing is merged yet, so the worktree stays, and the result says the merge is pending. - Merged with squash or rebase: the branch commits are not on the default branch, only their content. ADR 0029 lets prune use a content proof for that case, but its worktree row names commits only. Open question: does worktree removal accept the content proof too? ## Acceptance - A finish from a clean linked worktree, merged with a merge commit, removes the worktree once the forge proof passes. - A finish whose merge is only scheduled leaves the worktree and says the merge is pending. - With the forge out of reach, the worktree stays, and the result says the proof failed. - A dirty worktree stays. Depends on #666.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sixfold-space/madtea#691
No description provided.