Skip to content

fix: force worktree removal after successful draft-PR run - #77

Merged
suprie merged 1 commit into
mainfrom
fix/force-worktree-cleanup
Aug 5, 2026
Merged

fix: force worktree removal after successful draft-PR run#77
suprie merged 1 commit into
mainfrom
fix/force-worktree-cleanup

Conversation

@suprie

Copy link
Copy Markdown
Owner

Problem

Run loops fail on cleanup after a successful draft PR:

draft PR succeeded, but worktree cleanup failed: git worktree remove failed: fatal: '...' contains modified or untracked files, use --force to delete it

A successful run leaves the linked worktree dirty with post-push writes (e.g. .loopdeck/loops.md loop-state updates). git worktree remove refuses dirty worktrees without --force, so finalize_worktree flags the run as a cleanup failure even though the PR shipped.

Fix

  • worktree_remove now passes --force. The branch was already pushed for the draft PR, so the worktree holds nothing worth preserving; dirty leftovers are run artifacts.
  • Safe across callers: multi_agent.rs cleanup is already gated on worktree_is_pristine; finalize_worktree keep+flag fallback still catches genuine failures (locked/missing worktree).

Test

Adds worktree_remove_dirty_worktree regression test — dirties a worktree with an untracked file and asserts forced removal succeeds. Fails if --force is ever dropped.

Verified: cargo test worktree_lifecycle_add_list_remove, worktree_remove_dirty_worktree, finalize_worktree* all pass.

A successful run leaves the linked worktree dirty with post-push writes
(e.g. .loopdeck/loops.md loop-state updates), and plain 'git worktree
remove' refuses dirty worktrees. The branch was already pushed for the
draft PR, so the worktree holds nothing worth preserving; force the
removal so the run finishes clean instead of being flagged as a
cleanup failure.
Adds worktree_remove_dirty_worktree regression test.
@suprie
suprie marked this pull request as ready for review August 5, 2026 10:49
@suprie
suprie merged commit a73635e into mainAug 5, 2026
2 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@suprie