Repository navigation
feat(pool): add return --if-clean - #217
Conversation
…ould be lost Implements kunchenguid#216. 'treehouse return --if-clean' refuses, under the same pool lock as the reset and after any --if-lease-* condition, when the worktree has a live process, uncommitted changes, or commits that neither a remote-tracking ref nor the base branch contains. A refusal keeps the slot and its lease, exits 4 (ExitNotClean), and prints the blocker (processes, dirty, or unpushed) alone on stdout. It never prompts and never terminates processes. Git and jj slots are both covered through two new vcs.Backend methods; plain return is unchanged.
[Medium impact] The latest changes appear safe to merge. Reviews (10) · Last reviewed commit: "no-mistakes(document): Document clean-re..." · Reviewed by Greptile |
This comment has been minimized.
This comment has been minimized.
…rified reset target and HEAD and using the guarded reset, which rechecks HEAD and dirtiness before destructive updates. `go test ./internal/pool` and `git diff --check` pass; broader VCS tests timed out. Seeded ignored-file edits remain unresolved because the recorded inventory has paths but no seed-content baseline, so the CI finding is not fully addressed
… landed remote commits without the base-merge verdict, and made --if-clean recheck processes without terminating them. `go test ./cmd/ -run 'ReturnIfClean'`, `go test ./...`, and `git diff --check` pass. Seeded-file verification and post-checkout race coverage remain unimplemented; this phase is incomplete
Rework the --if-clean release so a refusal can never discard work or change the checkout, closing the races the earlier check-then-reset shape left open. - Record HEAD and the reset target before any check, and judge landedness against that exact commit (vcs.IsCommitLanded), so a commit landing mid-return moves HEAD off the snapshot and the reset refuses it. - Change nothing until every check passes: no git checkout (and so no checkout hooks), no detach, no process termination. - Re-run every check inside the guarded reset after HEAD is locked and compared, immediately before anything is removed (vcs.ResetWorktreeToRefVerified). - Treat a seeded file that differs from its source, or whose source is gone, as uncommitted work. - Never report success when the guarded reset fails: re-judge and report the blocker, or the failure itself. - Work on any remote-tracking ref has landed; no merged-into-base requirement. Plain return is unchanged. Adds one regression test per earlier review finding.
jj takes no lock that could hold the final verdict until its destructive steps, and each attempt to re-check inside jj's reset left a window. Take the "or refuse clearly" alternative from kunchenguid#216: --if-clean on a jj workspace refuses up front, before any change, with exit 4 and `unsupported`. Plain jj return is unchanged. - Remove the partial jj verified-reset path: jjvcs is back to its state on main, and the clean-return helpers (UncommittedWork, IsCommitLanded, ResetWorktreeToRefVerified) are Git-only vcs functions outside the Backend interface, which returns to 21 operations. - A tree already dirty when the git guarded reset takes HEAD's lock refuses even when the caller's verdict comes back empty, instead of reporting a reset that never ran. - The jj test asserts the refusal on clean, dirty and unpushed workspaces, each left untouched; docs and help say --if-clean is Git-only.
…ds now compare as the regular-file target text seeding writes, while copied symlinks are rejected. Late reset-step errors are no longer reclassified by a clean recheck; Git attempts to restore the recorded HEAD tree/index and reports the failed step. Updated design docs. Both requested test commands pass. Note: the requested forced post-write failure regression test was not added
…-if-clean and verifies/authenticates the original worktree before restoring; replaced worktrees are left untouched. Plain reset behavior is unchanged. Full `go test ./...` and the requested focused command pass. The requested replacement/post-write regression tests were not added
Add the two regression tests requested for the guarded reset: - A worktree directory replaced while a clean-only reset runs leaves the replacement checkout untouched. The test exposed that, without seeded files, nothing re-checked the directory before read-tree acted by pathname, so the clean-only reset now re-verifies the recorded directory identity right after its final checks, before the first write. - A failure after the tree was rewritten (forced at the HEAD publish step) restores the recorded commit's tree and index, leaves HEAD there, and reports the failure. Both tests fail with their guard removed and pass with it.
…registration resolver used by validation and cleanup authentication. Added a regression covering cleanup authentication and verified reset from another cwd. Targeted tests and `go test ./...` pass
On macOS the temp dir is reachable as both /tmp and /private/tmp, so the backlink computed across the two spellings climbed to / and resolved from any working directory; the test passed with the old lookup too. Resolve symlinks before computing the relative path, and assert the backlink does not resolve from the test's working directory. The test now fails on the old authenticateLinkedWorktree and passes with the shared resolver. Also restore ValidateWorktreeRegistration's doc comment, which the shared resolver had displaced, and document the resolver itself.
|
Speaking as Kun's firstmate: thanks @Dematom1 — this is the #216 implementation, and it's a nice, careful piece of work. I reviewed the diff (no workflow changes, no security concerns) and approved the fork CI runs on My read so far: contract-class opt-in — plain |
|
Speaking as Kun's firstmate: this is merged. Thank you @Dematom1 — really appreciate you taking the time on this. VISION: aligns (isolation/reuse: a clean-only return never recycles dirty, in-use, or unverifiable work; safe lifecycle: verifies against current Git/process state and leaves everything in place with a named blocker under uncertainty; interface: blocker on stdout, distinct exit 4; scope: local CLI primitive, no new dependency). Contract-class: opt-in — plain |
Intent
Implements #216: treehouse return --if-clean returns a worktree only when it has no uncommitted changes, no commits unreachable from a remote ref, and no running processes, checked against one HEAD snapshot under the slot lock; refuses with exit 4 and a machine-readable reason otherwise; git only, jj refuses as unsupported; plain return unchanged. Known limit: a process starting in the final instant before the reset cannot be fenced.
What Changed
treehouse return --if-cleanto release a slot only when its worktree has no uncommitted changes or commits unreachable from a remote ref, and no running processes; checks use one HEAD snapshot under the slot lock.returnunchanged.Risk Assessment
Testing
Targeted command-level tests drove the real CLI against isolated Git repositories, verifying clean return and required refusals; captured CLI test transcripts. The JJ unsupported case was attempted but skipped because no
jjexecutable is available; no visual surface applies.jj version; test skipped because jj is absent from PATH. No repository-local jj binary or credential/authority is supplied. Could not provide a live JJ…Evidence: Git return --if-clean end-to-end transcript
Evidence: JJ availability and attempted end-to-end test
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
internal/pool/pool.go:1060- If snapshotting the reset target or HEAD fails,resetIfCleanreturns the raw error rather thanNotCleanError. For example, a registered Git slot whose configured base ref has disappeared reachesIsWorktreeSafeToReset, errors, and exits 1 with no machine-readable blocker instead of the required exit 4 refusal. Treat this pre-write inability to verify as a clean-only refusal (and preserve ordinary-return behavior).✅ **Test** - passed
✅ No issues found.
jj version; test skipped because jj is absent from PATH. No repository-local jj binary or credential/authority is supplied. Could not provide a live JJ…go test ./cmd -run '^TestReturnIfClean' -count=1go test ./cmd -run '^(TestReturnIfClean|TestJJReturnIfClean)$' -count=1 -v(JJ case skipped: executable unavailable)jj version(command not found)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.