Clean up partial jj/git workspace on failed maudebox new#1
Open
eljaska wants to merge 1 commit into
Open
Conversation
`jj workspace add --name N -r REV TARGET` registers the workspace and creates the target directory before resolving REV. A bad revision (e.g. the user typing `--from main` in a repo whose default branch is `master`) leaves both behind, and the next attempt with the same name then fails on "Workspace named 'N' already exists" or "Target path already exists" — a hostile second error that obscures the real one and forces the user to manually run `jj workspace forget` plus `rm -rf` to recover. Wrap the workspace/worktree creation step so a failure triggers a silent rollback: `jj workspace forget` (or `git worktree remove --force`) in the source repo, plus `rm -rf` on the target path. Print a one-line notice only when something was actually rolled back, so a pre-creation failure (e.g. stale working copy) doesn't claim cleanup it didn't do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
jj workspace add --name N -r REV TARGETregisters the workspace and creates the target directory before resolvingREV. A bad revision (e.g.--from mainin a repo whose default branch ismaster) therefore leaves both behind, and the nextmaudebox new <same-name>attempt then trips over a hostile second error ("Workspace named 'N' already exists" / "Target path already exists") that obscures the real one and forces manual recovery withjj workspace forget+rm -rf.This change wraps the workspace/worktree creation step in
cmd::new::runso a failure triggers a silent rollback in the source repo:jj workspace forget <name>+rm -rf <target>git worktree remove --force <target>+rm -rf <target>(mostly defensive —git worktree addis more atomic)A one-line "Cleaned up partial workspace/worktree at: …" notice is printed only when at least one of the two operations actually removed state, so a pre-creation failure (e.g. stale working copy) doesn't falsely claim cleanup.
Test plan
No CI in this repo and no automated tests added for the cleanup helpers. Verified locally with my repo ~/Developer/jjuicy:
maudebox new test-late --from nonexistent ~/Developer/jjuicy true.jj workspace addregistered the workspace and created the directory, then failed on-r nonexistent. After cleanup: target directory gone,jj workspace listno longer showstest-late. Retry with a valid--fromsucceeds on the first try.cargo build --release+cargo install --path .clean.maudebox new <name> --from <valid-rev> <source> <cmd>still works on the happy path.🤖 This PR was created by Claude and approved by a human 🧍♂️