workspace: restore paths across undo and redo - #9989
Open
calebdw wants to merge 1 commit into
Open
Conversation
Keep workspace-store path entries when forgetting or deleting workspaces so undo has the local path metadata needed to restore the repo view correctly. For deleted workspaces, undo recreates the workspace directory and checks out the snapshotted working-copy commit. If the restore path already exists, undo fails before changing the repo view so redo cannot delete unrelated replacement contents. Redo removes directories for workspaces removed by a redone workspace delete operation.
calebdw
force-pushed
the
calebdw/push-ovnmnsqpuoum
branch
from
August 14, 2026 16:21
233430b to
c535fc3
Compare
Comment on lines
+284
to
+294
| fn workspace_restore_blocked_error( | ||
| workspace_name: &WorkspaceNameBuf, | ||
| workspace_path: &std::path::Path, | ||
| ) -> CommandError { | ||
| user_error(format!( | ||
| "Cannot restore workspace '{}' because directory '{}' already exists", | ||
| workspace_name.as_symbol(), | ||
| workspace_path.display() | ||
| )) | ||
| .hinted("Move the directory away, then retry `jj undo`.") | ||
| } |
Contributor
There was a problem hiding this comment.
nit: this also has only a single caller => inline.
Comment on lines
+420
to
+426
| if !workspace_root.exists() { | ||
| fs::create_dir(workspace_root).context(workspace_root)?; | ||
| } else if !file_util::is_empty_dir(workspace_root)? { | ||
| return Err(WorkspaceInitError::DestinationExists( | ||
| workspace_root.to_path_buf(), | ||
| )); | ||
| } |
Contributor
There was a problem hiding this comment.
nit: I don't think this is correct, see John's comment up in the stack.
Comment on lines
+472
to
+474
| .inspect_err(|_err| { | ||
| std::fs::remove_dir_all(jj_dir).ok(); | ||
| }) |
Contributor
There was a problem hiding this comment.
nit: a comment explaining why we're doing this should be helpful
Contributor
|
Undo/redo shouldn't affect unmanaged contents. Only view/operation objects (and managed working-copy files) should be updated by undo/redo. Can you add a warning when the user attempts to undo a workspace add/remove operation? |
Member
Author
|
@yuja, are you saying that you don't want |
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.
Keep workspace-store path entries when forgetting or deleting workspaces so undo has the local path metadata needed to restore the repo view correctly. For deleted workspaces, undo recreates the workspace directory and checks out the snapshotted working-copy commit. If the restore path already exists, undo fails before changing the repo view so redo cannot delete unrelated replacement contents.
Redo removes directories for workspaces removed by a redone workspace delete operation.
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
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.