Skip to content

fix(repos): worktrees prune removes only worktrees of merged pull requests - #2342

Merged
dan-petty merged 2 commits into
mainfrom
fix/2341-worktrees-prune-merged-pr
Oct 27, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/2341-worktrees-prune-merged-pr

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops repos worktrees prune now removes a worktree only when GitHub reports a merged pull request whose head commit is the tip of the worktree.

The old check was "another ref contains the tip". It removed new worktrees (their tip is the tip of main) and the worktrees of pushed branches with an open pull request. It refused every squash-merged worktree, because a squash never makes the branch tip an ancestor of main.

  • A worktree is removable when GET /repos/{repo}/commits/{tip}/pulls lists a pull request with merged_at set and head.sha equal to the tip. HTTP 422 (a commit that GitHub does not hold) keeps the worktree.
  • Local state decides first and costs no request: the main worktree, a locked worktree, a worktree with uncommitted paths and a worktree whose git status fails all stay. A worktree whose directory is gone is removed without a lookup.
  • prune removes nothing without --confirm. Without it, prune reads GitHub and lists what it would remove. --dry-run makes no request and prints the request plan. --dry-run with --confirm is refused.
  • A refused git worktree remove is reported as failed with the message of git, the directory stays, and the command exits 1. The shutil.rmtree fallback is deleted.
  • worktrees status loses the contained field and column. Its dirty field is null when git status fails.

Closes #2341

…uests (#2341)

A worktree is removable only when GitHub reports a merged pull request whose head is the tip of the worktree. The old check, that another ref contains the tip, removed new worktrees and the worktrees of pushed branches, and refused squash-merged ones.

Prune removes nothing without --confirm, reports a refused git worktree remove as failed instead of deleting the directory, and refuses a worktree whose git status fails.
@dan-petty

Copy link
Copy Markdown
Owner Author

Evidence for the draft:

  • devops ci fail-to-pass --base origin/main: 20 of the 22 tests in tests/test_repos_worktrees.py fail on origin/main and pass on this branch. The two that pass on both are the unchanged parser test and the unchanged dirty-count test.
  • devops ci typecheck and devops test run --changed (13 test files) pass.
  • Preview on the host that showed the defect (devops repos worktrees prune, which now removes nothing): of 71 worktrees, 66 are the head of a merged pull request (before: all 66 refused as unmerged). Kept: the main worktree, one locked review worktree, one locked agent worktree, two dirty worktrees, and one worktree with no merged pull request. The lookup takes 66 s, the same as the old run.
  • Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty marked this pull request as ready for review October 27, 2026 13:40
@dan-petty
dan-petty merged commit 23d864d into main Oct 27, 2026
16 checks passed
@dan-petty
dan-petty deleted the fix/2341-worktrees-prune-merged-pr branch October 27, 2026 14:01
dan-petty pushed a commit that referenced this pull request Oct 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.7.0](v0.6.5...v0.7.0)
(2026-10-27)


### Features

* **ci:** limit how many CPU-heavy gates run at once on one host
([#2339](#2339))
([115d1c1](115d1c1)),
closes [#2336](#2336)
* **ci:** make devops ci wait for a gate slot before a CPU-heavy check
([#2343](#2343))
([518db63](518db63)),
closes [#2336](#2336)
* **devcontainer:** onboard Kilo Code with a kilo.jsonc that exposes the
devops-cli MCP server
([#2332](#2332))
([3a6189e](3a6189e))
* **openspec:** commit the OpenSpec skills for Kilo Code
([#2334](#2334))
([9b4a824](9b4a824)),
closes [#2333](#2333)
* **repos:** add devops repos worktrees add that refuses a held issue
([#2348](#2348))
([a3b164d](a3b164d)),
closes [#2337](#2337)


### Bug Fixes

* **deps:** upgrade dnspython to fix GHSA-45c3-73f7-pv4m
([#2350](#2350))
([f50459d](f50459d))
* **k8s:** k8s apply renders the preview under --dry-run and starts no
child process
([#2328](#2328))
([16e26b0](16e26b0)),
closes [#2312](#2312)
* **k8s:** name the keyring entry when the Grafana admin password is
missing ([#2335](#2335))
([f9dcc79](f9dcc79))
* **repos:** worktrees prune removes only worktrees of merged pull
requests ([#2342](#2342))
([23d864d](23d864d)),
closes [#2341](#2341)
* **scan:** keep scan progress off stdout when the output format is json
([#2331](#2331))
([1b17048](1b17048)),
closes [#2216](#2216)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to 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.

fix(repos): worktrees prune removes worktrees in use, refuses squash-merged ones and removes by default

1 participant