Skip to content

Commit

Permalink
cli: fix "workspace add --at-op" to set up new working copy properly
Browse files Browse the repository at this point in the history
Because new workspace is created for the new operation forked from the --at-op
operation, the new working copy should be writable.
  • Loading branch information
yuja committed Jul 24, 2024
1 parent b76947c commit d7c1b97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ impl CommandHelper {
workspace: Workspace,
repo: Arc<ReadonlyRepo>,
) -> Result<WorkspaceCommandHelper, CommandError> {
WorkspaceCommandHelper::new(ui, self, workspace, repo)
let loaded_at_head = self.global_args.at_operation == "@";
WorkspaceCommandHelper::new(ui, self, workspace, repo, loaded_at_head)
}
}

Expand Down Expand Up @@ -499,13 +500,13 @@ impl WorkspaceCommandHelper {
command: &CommandHelper,
workspace: Workspace,
repo: Arc<ReadonlyRepo>,
loaded_at_head: bool,
) -> Result<Self, CommandError> {
let settings = command.settings.clone();
let commit_summary_template_text =
settings.config().get_string("templates.commit_summary")?;
let revset_aliases_map = revset_util::load_revset_aliases(ui, &command.layered_configs)?;
let template_aliases_map = command.load_template_aliases(ui)?;
let loaded_at_head = command.global_args.at_operation == "@";
let may_update_working_copy = loaded_at_head && !command.global_args.ignore_working_copy;
let working_copy_shared_with_git = is_colocated_git_workspace(&workspace, &repo);
let path_converter = RepoPathUiConverter::Fs {
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ fn cmd_workspace_add(
)?;

// Copy sparse patterns from workspace where the command was run
let mut new_workspace_command = WorkspaceCommandHelper::new(ui, command, new_workspace, repo)?;
let loaded_at_head = true;
let mut new_workspace_command =
WorkspaceCommandHelper::new(ui, command, new_workspace, repo, loaded_at_head)?;
let (mut locked_ws, _wc_commit) = new_workspace_command.start_working_copy_mutation()?;
let sparse_patterns = old_workspace_command
.working_copy()
Expand Down
16 changes: 9 additions & 7 deletions cli/tests/test_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,18 @@ fn test_workspaces_add_at_operation() {
Parent commit : rlvkpnrz 0dbaa19a 2
"###);

// FIXME: --at-op should disable snapshot in the main workspace, but the
// newly created workspace should still be writable.
// --at-op should disable snapshot in the main workspace, but the newly
// created workspace should still be writable.
std::fs::write(main_path.join("file3"), "").unwrap();
let stderr = test_env.jj_cmd_failure(
let (_stdout, stderr) = test_env.jj_cmd_ok(
&main_path,
&["workspace", "add", "--at-op=@-", "../secondary"],
);
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
Created workspace in "../secondary"
Error: This command must be able to update the working copy.
Hint: Don't use --at-op.
Working copy now at: rzvqmyuk a4d1cbc9 (empty) (no description set)
Parent commit : qpvuntsm 3364a7ed 1
Added 1 files, modified 0 files, removed 0 files
"###);
let secondary_path = test_env.env_root().join("secondary");

Expand All @@ -188,8 +189,8 @@ fn test_workspaces_add_at_operation() {
insta::assert_snapshot!(stdout, @r###"
Working copy changes:
A file4
Working copy : zsuskuln 7df5cfc8 (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
Working copy : rzvqmyuk 2ba74f85 (no description set)
Parent commit: qpvuntsm 3364a7ed 1
"###);
insta::assert_snapshot!(stderr, @r###"
Concurrent modification detected, resolving automatically.
Expand All @@ -201,6 +202,7 @@ fn test_workspaces_add_at_operation() {
○ resolve concurrent operations
├─╮
○ │ commit cd06097124e3e5860867e35c2bb105902c28ea38
│ ○ create initial working-copy commit in workspace secondary
│ ○ add workspace 'secondary'
├─╯
○ snapshot working copy
Expand Down

0 comments on commit d7c1b97

Please sign in to comment.