Skip to content

workspace: restore paths across undo and redo - #9989

Open
calebdw wants to merge 1 commit into
calebdw/push-plyzvynpqkqvfrom
calebdw/push-ovnmnsqpuoum
Open

workspace: restore paths across undo and redo#9989
calebdw wants to merge 1 commit into
calebdw/push-plyzvynpqkqvfrom
calebdw/push-ovnmnsqpuoum

Conversation

@calebdw

@calebdw calebdw commented Aug 14, 2026

Copy link
Copy Markdown
Member

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:

  • 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 14, 2026 16:08
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
calebdw force-pushed the calebdw/push-ovnmnsqpuoum branch from 233430b to c535fc3 Compare August 14, 2026 16:21

@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
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`.")
}

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.

nit: this also has only a single caller => inline.

Comment thread lib/src/workspace.rs
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(),
));
}

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.

nit: I don't think this is correct, see John's comment up in the stack.

Comment thread lib/src/workspace.rs
Comment on lines +472 to +474
.inspect_err(|_err| {
std::fs::remove_dir_all(jj_dir).ok();
})

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.

nit: a comment explaining why we're doing this should be helpful

@yuja

yuja commented Aug 14, 2026

Copy link
Copy Markdown
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?

@calebdw

calebdw commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

@yuja, are you saying that you don't want jj undo to be able to undo a jj workspace delete <workspace>?

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.

3 participants