Skip to content

fix(cli): keep repos/ clones on the workspace and read the current worktree everywhere (#612, #613) - #614

Merged
dan-petty merged 1 commit into
release/v0.2.23from
fix/612-worktree-resolution-followup
Sep 25, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.23from
fix/612-worktree-resolution-followup

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

Fixes two defects in work delivered for v0.2.23.

#612: #585's worktree resolution regressed clones under repos/ and missed stale worktrees. #585 fixed #582 for nested worktrees, but its resolver stopped at the first directory with its own .git. That contradicted what #582 required.

Run from Before #585: gate / data #585: gate / data This PR: gate / data
Nested worktree under .claude/worktrees/ main / main worktree / main worktree / main
Clone under repos/ workspace / workspace clone / clone workspace / workspace
Worktree of that clone workspace / workspace clone worktree / clone workspace / workspace
Nested worktree, pruned or checkout moved main / main main / main worktree / main
Relative-path worktree main / main worktree / main worktree / main

"Gate" is find_worktree_root and "data" is main_worktree_root. The table rows come from an acceptance probe over eleven real layouts, which this PR matches exactly.

#613: other commands still read the main checkout from a nested worktree. devops ai repomap, devops ai diagram arch, devops ai ast graph (which came back empty, because the checkout's .gitignore excludes .claude/), devops review auto-fix, devops tf deploys and Kube-linter locations all acted on the main checkout.

Changes

  • find_worktree_root (core/repo.py) stops at the nearest linked worktree, live or stale, and otherwise keeps the workspace root. Relative-path worktrees, bare-repository worktrees, and .git files that are unreadable or not UTF-8 are handled. main_worktree_root starts from the workspace root again. is_stale_linked_worktree is new.
  • Gate (commands/ci.py):
    • names its root before the cache lookup and for every single check, such as devops ci test run by the pre-commit hook, except --help;
    • warns from a stale worktree with the fix for each cause: git worktree repair <path> if the checkout moved, or move it aside and git worktree add if it was pruned;
    • resolves its root on each call, dropping the import-time _ROOT.
  • Current-worktree readers: repomap, diagram, AST graph, review auto-fix, tf and Kube-linter use find_worktree_root. Kube-linter's parser is split into helpers to stay within the complexity cap.
  • devops tf deploy guard: a worktree lacks the main checkout's untracked terraform.tfstate, so apply there would plan to create every resource again. The deploy now stops when auto-approved, asks otherwise (default no), and only warns on a dry run. A remote backend is never stopped.
  • Roadmap and task files: the Gate Checks the Worktree It Runs In, Not the Main Checkout (devops ci) #582 entry moves to v0.2.23 with its issue number and a note on what this corrects. Its Deliverable wording had prescribed the stop-at-any-.git rule. Worktree Gate Resolution Keeps repos/ Clones on the Workspace and Checks Stale Worktrees #612 and Code-Reading AI, IaC and Scan Commands Use the Worktree They Run In #613 are recorded as delivered, and both task files are included.

Verification

  • Real-git tests cover:
    • nested, outside, relative-path, pruned and moved-checkout worktrees;
    • clones under repos/ and their worktrees, and submodules;
    • bare repositories and undecodable .git files.
  • A real ruff test shows that a lint error only in the worktree fails the check, while one only in the main checkout does not.
  • A test runs the stale-worktree warning's repair command and checks that it restores a worktree whose checkout moved.
  • Each Code-Reading AI, IaC and Scan Commands Use the Worktree They Run In #613 command is tested from a nested worktree, including every branch of the tf guard.
  • The change went through four review rounds from correctness, test and conventions angles. Each finding was checked by an independent skeptic before it was fixed.
  • The full devops ci gate passed on push.

Closes #612
Closes #613

…rktree everywhere (#612, #613)

#585 fixed #582 for nested worktrees, but its resolver stopped at the
first directory with its own .git. A clone under repos/ and each worktree
of it then resolved to the clone, for the gate and for shared data, which
landed in the clone's working tree. A nested worktree whose git directory
was pruned, or whose checkout moved, still gated the main checkout.

find_worktree_root now stops at the nearest linked worktree, live or
stale, and otherwise keeps the workspace root, so the main checkout,
clones under repos/, their worktrees and submodules resolve as before
#585. main_worktree_root shares the workspace's data with them again.
The gate names the root it checks before the cache lookup and for every
single check, warns from a stale worktree with the fix for each cause,
and resolves its root on each call instead of at import.

Commands that read, index or deploy the current tree now use it too:
repomap, the architecture diagram, the AST graph (which came back empty
from a nested worktree), review auto-fix, tf deploys and Kube-linter
locations. A tf deploy from a worktree that lacks the main checkout's
untracked local state stops when auto-approved and asks otherwise, since
apply would plan to create every resource again.

Every case is tested against real git layouts, and an acceptance probe
over eleven layouts matches the required gate and data roots. The #582
roadmap entry moves to v0.2.23 with a note on what #612 corrected.

Closes #612
Closes #613
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.

1 participant