Skip to content

workspace delete: remove workspace directory - #9981

Open
calebdw wants to merge 1 commit into
mainfrom
calebdw/push-plyzvynpqkqv
Open

workspace delete: remove workspace directory#9981
calebdw wants to merge 1 commit into
mainfrom
calebdw/push-plyzvynpqkqv

Conversation

@calebdw

@calebdw calebdw commented Aug 13, 2026

Copy link
Copy Markdown
Member

Add jj workspace delete for destructive workspace cleanup. jj workspace forget remains non-destructive and only stops tracking the workspace in the repo.

jj workspace delete snapshots each target workspace before removal, forgets it from the repo view, and removes its directory from disk. It requires explicit workspace names and refuses --ignore-working-copy, --at-operation, --no-integrate-operation, unreachable workspaces, and the main workspace. Deleting the current workspace is also rejected on Windows, where removing the process's cwd is not viable; Unix continues to allow deleting the current non-main workspace.

Ignored files are still deleted as part of directory removal, matching the explicit destructive semantics of workspace delete.

Relates to #9941 (comment)

CC: @yuja

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added/updated tests to cover my changes
  • I fully understand the code that I am submitting (what it does, how it works, how it's organized), including any code drafted by an LLM.
  • For any prose generated by an LLM, I have proof-read and copy-edited with an eye towards deleting anything that is irrelevant, clarifying anything that is confusing, and adding details that are relevant. This includes, for example, commit descriptions, PR descriptions, and code comments.

@calebdw
calebdw requested a review from a team as a code owner August 13, 2026 15:13
@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch from 50748a2 to cb1f8f3 Compare August 13, 2026 15:18
@PhilipMetzger

Copy link
Copy Markdown
Contributor

cc @joshka @steveklabnik since you also argued for that behavior.

@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch 3 times, most recently from 459a4a9 to 9cb08bd Compare August 13, 2026 16:24
@scott2000

Copy link
Copy Markdown
Contributor

To me, forget sounds like it should be non-destructive, so it's surprising it would delete anything (for instance, jj bookmark forget doesn't delete the bookmark from a remote). If anything, I would be in favor of having a separate jj workspace delete command that deletes the workspace (similar to how we also have jj bookmark delete).

This is safe because jj always snapshots the working-copy state into a commit before forgetting.

I don't think this is accurate always, since there could be ignored files that the user doesn't want to lose.

@ShiroKSH ShiroKSH left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deletes un-snapshotted changes from a non-current workspace.

Comment thread cli/src/commands/workspace/forget.rs Outdated
@joshka

joshka commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

If anything, I would be in favor of having a separate jj workspace delete command that deletes the workspace

+1 (bikeshed) The opposite of add is generally remove if looking for a good word for this and aligns well with rm meaning remove.

To me, forget sounds like it should be non-destructive, so it's surprising it would delete anything

Deletion is fine if and only if things are snapshotted first and have astrong path to properly being handled - i.e. jj workspace <delete/remove> foo; jj undo does the right thing. The problem with that is that it runs into untracked files fairly easily, so a I know what I'm requesting here is probably a reasonable thing, and that's either jj workspace remove or jj workspace forget --remove - whichever is in pattern with other commands.

There's a few of things that should probably shape thinking on this:

#9786 - I owe some updates
#9787 - needs a re-review after changes
#5271

As a general rule here, the test coverage should be over both non default and default workspaces and include testing the undo.

@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch from 9cb08bd to 86877b7 Compare August 14, 2026 09:57
@calebdw
calebdw requested a review from ShiroKSH August 14, 2026 10:03
@calebdw

calebdw commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

This deletes un-snapshotted changes from a non-current workspace.

Thanks, I've fixed and added tests for this 👍

To me, forget sounds like it should be non-destructive, so it's surprising it would delete anything (for instance, jj bookmark forget doesn't delete the bookmark from a remote). If anything, I would be in favor of having a separate jj workspace delete command that deletes the workspace (similar to how we also have jj bookmark delete).

I'm not sure I see the need for both a workspace forget and a workspace delete/remove command---but if the maintainers want then I can rename forget or create a new command for this. Not sure that the whole forget vs. delete applies to workspaces like it does to remote bookmarks---for a local-only bookmark, forget and delete both yield the same end result

I don't think this is accurate always, since there could be ignored files that the user doesn't want to lose.

Then don't forget the workspace until you're ready? Or move the ignored files out then forget? Not sure I can really fathom an instance where you need to forget the workspace but leave all the files behind:

  • it's not like you can re-add the same workspace there in the future because the directory is not empty
  • it's not like you're going to be modifying them as the files are no longer tracked

@joshka

joshka commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

it's not like you can re-add the same workspace there in the future because the directory is not empty

this should be allowed IMO

it's not like you're going to be modifying them as the files are no longer tracked

Something to think about here is how the various pieces here compose, like what if I want to forget a workspace that is on a network share that I don't have access to, then move that elsewhere to somewhere I do have access and readd it. The bits don't exist in a vacuum here. I think that's some of the context about why forget and removing the files was seen as separable (I could be wrong, I haven't dug deep on that one)

@ShiroKSH ShiroKSH left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous P1 is fixed: the new regression test preserves an unsnapshotted change in a non-current workspace. A separate data-loss path remains below.

Comment thread cli/src/commands/workspace/forget.rs Outdated
@calebdw calebdw changed the title workspace forget: remove workspace directory on forget workspace delete: remove workspace directory Aug 14, 2026
@calebdw
calebdw requested review from ShiroKSH and yuja August 14, 2026 14:56
@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch from 86877b7 to 36584d4 Compare August 14, 2026 14:56

@ShiroKSH ShiroKSH left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The split into non-destructive workspace forget and guarded workspace delete addresses the preceding review. Two P1s remain in the new undo/redo and current-workspace paths.

Comment thread cli/src/commands/undo.rs Outdated
Comment thread cli/src/commands/workspace/delete.rs

@PhilipMetzger PhilipMetzger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor stuff

Comment thread cli/src/commands/undo.rs Outdated
Comment thread cli/src/commands/undo.rs Outdated
Comment thread cli/src/commands/undo.rs Outdated
Comment thread cli/src/commands/workspace/forget.rs Outdated
Comment thread cli/src/commands/workspace/delete.rs Outdated
Comment thread cli/src/commands/workspace/delete.rs Outdated
Comment thread cli/src/commands/workspace/forget.rs Outdated
Comment thread cli/src/commands/undo.rs Outdated
@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch from 36584d4 to 7828670 Compare August 14, 2026 16:08
@calebdw

calebdw commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

I've moved the undo/redo changes into its own commit since that's a bit more involved

Add `jj workspace delete` for destructive workspace cleanup while keeping
`jj workspace forget` non-destructive. The delete command snapshots target
workspaces before removing them from the repo view and deleting their
workspace directories.

Reject destructive operation modes, unreachable workspaces, the main
workspace, and current workspace deletion on Windows where removing the
process's cwd is not viable.

Update docs, CLI help, and workspace tests for the new command.
@calebdw
calebdw force-pushed the calebdw/push-plyzvynpqkqv branch from 7828670 to a1cfdd1 Compare August 14, 2026 16:21

@ShiroKSH ShiroKSH left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit workspace names and Windows guard resolve the prior current-directory P1. The undo path required for a destructive workspace delete is still broken.


workspace_command = command.workspace_helper_no_snapshot(ui).await?;

forget_workspaces(ui, &mut workspace_command, &delete_ws, "delete").await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] workspace delete must not reuse the irreversible forget metadata path until undo can restore it. This helper deletes the workspace-store entry before the operation, but the unchanged jj undo only restores the repo view. Repro on this head: create secondary, run jj workspace delete secondary, then jj undo. jj workspace list shows secondary, but its directory is still missing, jj workspace root --name secondary reports no recorded path, and jj workspace add --name secondary ../secondary fails because the name is already tracked. That leaves the user unable to recover the deleted workspace through the promised operation history. Retain the path metadata and restore the workspace on undo (with a safe redo), or defer this command until that behavior ships; add the regression test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShiroKSH, did you see the second commit in the stack? I was trying to keep these separate but I suppose I can just combine the PRs if you want

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.

6 participants