Repository navigation
Description
Problem Description
devops repos worktrees prune --confirm removes a clean worktree whose tip heads a merged pull request. It does not count the files that .gitignore hides, and it does not limit itself to the managed folder .data/agent/worktrees. git worktree remove deletes the ignored files of a worktree. So prune can delete agent scratch files, a local .env or other ignored data, and it removes the worktrees that other tools made outside the repository.
#4092 fixed this for the reclaim step of devops repos worktrees add only:
- The reclaim keeps a worktree outside the managed folder and a worktree that holds ignored files (
src/devops_cli/git/worktree_add.py:259and:274, which callscount_ignored_paths). - Prune decides with
_decided_by_local_stateand_decide(src/devops_cli/git/worktree_inventory.py:386-433). These functions read only main, current directory,--force, locked, prunable and dirty. No caller of prune usescount_ignored_paths(src/devops_cli/git/worktree_inventory.py:227), although its docstring says that the remove deletes that data (fix(repos): worktree cleanup keeps other worktrees #4092).
Reproduction Steps
- Make a worktree of a branch whose pull request is merged, outside
.data/agent/worktrees, for example under the worktree folder of another tool. - Put a file that
.gitignorehides in it, for example.data/agent/scratch/note.md. - Run
uv run devops repos worktrees prune. - The preview lists the worktree as removable ("head of merged pull request #N").
- Run it again with
--confirm. The worktree and the ignored file are gone.
Seen on 2026-11-19: one prune --confirm removed 5 worktrees under the worktree folder of another agent tool in the home directory, some agent worktrees under .claude/worktrees, and one worktree under .data/agent/worktrees. The branches stay, so no commit is lost. Whether the removed worktrees held ignored files is not known.
Expected vs Actual Behavior
Expected: prune applies the same scope rules as the reclaim of #4092. Without --force, it refuses a worktree that holds ignored files ("holds N ignored paths") and a worktree outside the managed folder ("outside .data/agent/worktrees"). The preview names each refusal. --force stays the way to remove every worktree.
Actual: prune removes each clean worktree at the head of a merged pull request, in any folder, with its ignored files.
Acceptance criteria:
- A test makes a clean worktree at a merged head that holds one ignored file. Prune refuses it and names the ignored count.
- A test makes a clean worktree at a merged head outside the managed folder. Prune refuses it and names the folder.
- Prune and the reclaim decide scope with one shared function, so the two rules cannot drift.
- The help text of
pruneandCONTRIBUTING.mdsay which worktrees prune removes.
Environment Diagnostics
devops-cli at main 0057c41 (2026-11-19). The command is uv run devops repos worktrees prune --confirm.
Logs, Traces, or Terminal Output
removed <home>/.gemini/antigravity/worktrees/devops-cli/pr4117_evaluate_fix (1.1 GB)
removed <home>/.gemini/antigravity/worktrees/devops-cli/pr4138_evaluate_fix (1.2 GB)
removed <home>/.gemini/antigravity/worktrees/devops-cli/pr4146_evaluate_fix (1.1 GB)
removed <home>/.gemini/antigravity/worktrees/devops-cli/pr4155_openspec_plans (1.1 GB)
removed <home>/.gemini/antigravity/worktrees/devops-cli/pr4356_evaluate_fix (1.1 GB)
Dependencies
None.
Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Searches found only gtr (git-worktree-runner) and its wrappers gtri and gtr.nvim: they list, create and clean merged worktrees but decide no scope and refuse no ignored files or foreign folders, and gtr is archived.
Lacks:
- No refusal of a worktree that holds ignored paths
- No managed-folder scope outside .data/agent/worktrees
- No shared scope function with the add reclaim
- No prune help text or CONTRIBUTING.md scope paragraph
Proposed design
Problem statement
devops repos worktrees prune --confirm removes a clean worktree whose tip heads a merged pull request in any folder, with the files that .gitignore hides. The reclaim of devops repos worktrees add already keeps a worktree outside .data/agent/worktrees and a worktree that holds ignored paths (#4092), but prune does not use that rule. Prune can thus delete agent scratch files, a local .env and worktrees that other tools made outside the repository. This item makes prune and the reclaim take the scope rule from one shared function, and it states the scope in the help text and in CONTRIBUTING.md.
Acceptance criteria
Requirement: Ignored paths keep a worktree
devops repos worktrees prune SHALL refuse a clean worktree at the head of a merged pull request when the worktree holds ignored paths.
Scenario: One ignored file in the managed folder
- WHEN a test runs prune on a clean worktree under
.data/agent/worktreesat a merged head that holds one file that.gitignorehides - THEN the preview keeps the worktree with the reason
holds 1 ignored path, and--confirmleaves the directory in place
Requirement: A foreign folder keeps a worktree
devops repos worktrees prune SHALL refuse a worktree whose path is not under .data/agent/worktrees.
Scenario: Worktree in another tool's folder
- WHEN a test runs prune on a clean worktree at a merged head in a folder outside
.data/agent/worktrees - THEN the preview keeps the worktree with a reason that names
.data/agent/worktrees, and--confirmleaves the directory in place
Requirement: One scope function for prune and reclaim
The prune decision and the reclaim of devops repos worktrees add MUST take the scope refusal from one function.
Scenario: Both callers return the shared refusal
- WHEN a test calls the shared scope function, the prune decision and the reclaim with one worktree outside the managed folder, and with one worktree that holds one ignored path
- THEN each caller returns the same refusal text as the shared function for each worktree, so the two scope rules cannot drift
Requirement: Force still removes a refused worktree
devops repos worktrees prune --confirm --force SHALL remove a clean worktree at a merged head that the scope rules refuse.
Scenario: Force removes a worktree with an ignored file
- WHEN a test runs prune with
--confirm --forceon a clean worktree at a merged head under.data/agent/worktreesthat holds one ignored file - THEN the worktree directory is gone
Requirement: Prune help states the scope
The help text of devops repos worktrees prune MUST state which worktrees the command removes.
Scenario: Help output names the folder and the force flag
- WHEN a test runs
devops repos worktrees prune --help - THEN the output names
.data/agent/worktrees, the ignored-path refusal and--force
Requirement: CONTRIBUTING.md states the scope
CONTRIBUTING.md MUST state which worktrees devops repos worktrees prune removes.
Scenario: The documentation check passes
- WHEN a person runs
uv run devops ci docsafter the edit - THEN the command exits 0 and reports no documentation problem
Existing Tool Considered
None. The alternatives check of 2026-11-19 records the verdict none: no open, maintained tool or library covers the need. The alternatives block in the issue body lists the tools it considered and what they lack. The change is therefore in-repo code: one shared scope function of about 40 lines with tests. The written cost is about 1,500 tokens to build, keep and fix that code until it matches the tool, and about 30 minutes.
Key questions
- Which module holds the shared scope decision, and which callers use it?: A public function
scope_refusal(entry, *, managed_root)insrc/devops_cli/git/worktree_inventory.py, besidecount_ignored_pathsat line 227._decideat line 417 gains amanaged_rootparameter and calls it after_decided_by_local_stateand before the merged-pull read. The reclaim atsrc/devops_cli/git/worktree_add.py:259and:274calls it in place of its two inline checks. (best practice) [sources: src/devops_cli/git/worktree_inventory.py:227, src/devops_cli/git/worktree_inventory.py:386, src/devops_cli/git/worktree_inventory.py:417, src/devops_cli/git/worktree_add.py:259, src/devops_cli/git/worktree_add.py:274]- Chosen: A function in
worktree_inventory.py. The module already holdscount_ignored_pathsand_decide, so one import serves both callers and no new module appears. - Rejected: A method on
WorktreeEntry. The rule needs the managed root and a git call for the ignored count, which a value object does not hold. - Rejected: A new module
worktree_scope.py. One small function does not justify a module, and the repository keeps a rule beside its owner.
- Chosen: A function in
- In which order do the two scope rules run, and which reason does the preview show?: Outside the managed folder first, then the ignored paths. The order matches the reclaim at
src/devops_cli/git/worktree_add.py:259(outside) and:274(ignored), so both callers print the same reason. The outside check also avoids a git call for a foreign worktree. The ignored reason uses the singular and plural form of the existing dirty reason:holds 1 ignored pathandholds 3 ignored paths. (best practice) [sources: src/devops_cli/git/worktree_add.py:259, src/devops_cli/git/worktree_add.py:274, src/devops_cli/git/worktree_inventory.py:386]- Chosen: Outside first, then ignored. It keeps the reason text of the reclaim and it saves a git call for a worktree outside the managed folder.
- Rejected: Ignored first, then outside. It changes the reason that a foreign worktree shows and it adds a git call for each foreign worktree.
- Does
--forcebypass the scope rules?: Yes. The scope check runs after_decided_by_local_state, which returnsremovable=Truewith the reasonforcedwhen--forceis set. The main worktree and the worktree that holds the current directory stay kept, as before. (best practice) [sources: src/devops_cli/git/worktree_inventory.py:386, src/devops_cli/git/worktree_inventory.py:417]- Chosen:
--forcebypasses the scope rules. The issue states that--forcestays the way to remove every worktree, and the existing local-state check already gives force precedence. - Rejected:
--forcekeeps outside and ignored worktrees. It gives the user no way to remove a refused worktree, which contradicts the expected behavior of the issue.
- Chosen:
- Which function counts the ignored paths of a worktree?:
count_ignored_pathsatsrc/devops_cli/git/worktree_inventory.py:227. Its docstring says thatgit worktree removedeletes that data (fix(repos): worktree cleanup keeps other worktrees #4092). [sources: src/devops_cli/git/worktree_inventory.py:227, src/devops_cli/git/worktree_add.py:274] - Where does
CONTRIBUTING.mdstate the scope of prune?: In section 4, Git Hygiene & Branch Management, as one paragraph beside the branch rules. (best practice) [sources: CONTRIBUTING.md, CONTEXT.md]- Chosen: Section 4 of
CONTRIBUTING.md. A contributor reads the git and worktree rules there, and the section is a hand-written document. - Rejected:
docs/CLI_REFERENCE.md. It is a generated document, and nobody edits it by hand.
- Chosen: Section 4 of
- Does the change need a new dependency or tool?: No. Git's own
git worktreeandgit status --ignoredplumbing already provide the removal and the ignored list, and the project wraps them incount_ignored_paths. (best practice) [sources: src/devops_cli/git/worktree_inventory.py:227, src/devops_cli/git/worktree_add.py:274]- Chosen: Keep the in-repo wrapper of git. Git's plumbing covers the removal and the ignored list, and the alternatives check found no covering library.
- Rejected: Add a worktree manager library. The alternatives check found only gtr and its wrappers, which are archived and decide no scope.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 19, 2026
The prune command deletes user data (ignored files, foreign worktrees) when run with --confirm, causing data loss.Both apply the same scope rules (ignore count, managed folder) to worktree removal, but #4092 fixed the reclaim step while this candidate fixes the prune command path.devops-cli-service commentedon Nov 19, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Nov 19, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 19, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 19, 2026
Plan state: branch
fix/6435-worktrees-prune-deletes-ignored-and-foreign, draft pull request #6477. The pull request plans the item and closes no issue. The stage job and the step fix-plan edit this comment, and a comment of each run tells what the run did.The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:
A model review of the plan found these points. They stop no draft, and a person judges them:
verify_format tasks (2): Group 2 changes the prune fixtures and expectations intests/git/test_repos_worktrees.pyandtests/git/test_repos_worktrees_reclaim.py, but its verify runs onlytests/git/test_repos_worktrees_reclaim_scope.py, so the tests it changes are never run and a broken fixture move passes the group. Evidence: "uv run devops ci test tests/git/test_repos_worktrees_reclaim_scope.py"missing_pathat tasks (2): Group 2 givesplan_prunea new first parameter and tells the reader to pass the root inreclaim_merged_worktrees, butsrc/devops_cli/git/worktree_add.py, which holds that caller, is missing from the group'schanges. The existing callplan_prune(entries, repo=repo)then bindsentriesto the new root parameter and breaks the group's own dry-run tests. Evidence: "Passroottoplan_pruneinworktrees_pruneand inreclaim_merged_worktrees"false_premiseat proposal (why): The plan states as fact that prune has already removed agent scratch files and a local.env, but the issue says whether the removed worktrees held ignored files is not known; the issue only says prune can delete such data. Evidence: "It has removed agent scratch files, a local.envand worktrees that other tools made outside the repository (fix(repos): worktrees prune deletes ignored and foreign trees #6435)."spec_delta_wrongat spec repos-worktrees-prune (The prune help states the scope): The added requirement makes the help say that--forceremoves every worktree but the main one, but the base spec keeps the worktree that holds the current directory also under--force, so the help text this requirement asks for would state a false rule. Evidence: "and that--forceremoves every worktree but the main one"otherat design (decisions): The scope check runs after_decided_by_local_state, which returnsremovable=Truefor a prunable worktree, so prune still removes a worktree outside the managed folder whose directory is missing, while the reclaim keeps it (its requirement says "also when its directory is missing"). The shared function therefore does not keep the two rules from drifting for that case. Evidence: "return _Decision(entry, removable=True, reason="directory is missing")"3 remaining items
docs(openspec): plan #6435 Refuse ignored and foreign worktrees in prune
docs(openspec): revise the plan of #6435 for data and the managed folder
docs(openspec): state the review fixes of #6435 in the plan
docs(openspec): plan #6435 Refuse ignored and foreign worktrees in prune
docs(openspec): revise the plan of #6435 for data and the managed folder
docs(openspec): state the review fixes of #6435 in the plan
devops-cli-service commentedon Nov 20, 2026
Released in v0.182.3: https://github.com/dan-petty/devops-cli/releases/tag/v0.182.3
devops-cli-service commentedon Nov 20, 2026
Live since 2026-11-20 06:31 UTC