From d7c1b97418e2a03176d55d5fe39714758c7ec57c Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 22 Jul 2024 23:06:49 +0900 Subject: [PATCH] cli: fix "workspace add --at-op" to set up new working copy properly Because new workspace is created for the new operation forked from the --at-op operation, the new working copy should be writable. --- cli/src/cli_util.rs | 5 +++-- cli/src/commands/workspace.rs | 4 +++- cli/tests/test_workspaces.rs | 16 +++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index eff1ca76fe..8c00c4720a 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -378,7 +378,8 @@ impl CommandHelper { workspace: Workspace, repo: Arc, ) -> Result { - WorkspaceCommandHelper::new(ui, self, workspace, repo) + let loaded_at_head = self.global_args.at_operation == "@"; + WorkspaceCommandHelper::new(ui, self, workspace, repo, loaded_at_head) } } @@ -499,13 +500,13 @@ impl WorkspaceCommandHelper { command: &CommandHelper, workspace: Workspace, repo: Arc, + loaded_at_head: bool, ) -> Result { 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 { diff --git a/cli/src/commands/workspace.rs b/cli/src/commands/workspace.rs index 8f5e4b4246..bf8cdcc178 100644 --- a/cli/src/commands/workspace.rs +++ b/cli/src/commands/workspace.rs @@ -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() diff --git a/cli/tests/test_workspaces.rs b/cli/tests/test_workspaces.rs index 874f8f5940..94217fbdfe 100644 --- a/cli/tests/test_workspaces.rs +++ b/cli/tests/test_workspaces.rs @@ -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"); @@ -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. @@ -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