From b0f5b920dd857a39a7a913de4e033de10e38daf7 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 17 Feb 2024 09:04:21 -0800 Subject: [PATCH] cli: make new workspace inherit sparse pattern from old workspace --- CHANGELOG.md | 3 +++ cli/src/commands/workspace.rs | 17 +++++++++++++++++ cli/tests/test_workspaces.rs | 7 +++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45693ab275c..8cdc0116ce4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#2971](https://github.com/martinvonz/jj/issues/2971)). This may become the default depending on feedback. +* When creating a new workspace, the sparse patterns are now copied over from + the current workspace. + ### Fixed bugs * On Windows, symlinks in the repo are now materialized as regular files in the diff --git a/cli/src/commands/workspace.rs b/cli/src/commands/workspace.rs index 5158ab8241f..0ea79dd77c0 100644 --- a/cli/src/commands/workspace.rs +++ b/cli/src/commands/workspace.rs @@ -44,6 +44,8 @@ use crate::ui::Ui; /// Each workspace has its own working-copy commit. When you have more than one /// workspace attached to a repo, they are indicated by `@` in /// `jj log`. +/// +/// Each workspace also has own sparse patterns. #[derive(Subcommand, Clone, Debug)] pub(crate) enum WorkspaceCommand { Add(WorkspaceAddArgs), @@ -54,6 +56,8 @@ pub(crate) enum WorkspaceCommand { } /// Add a workspace +/// +/// Sparse patterns will be copied over from the current workspace. #[derive(clap::Args, Clone, Debug)] pub(crate) struct WorkspaceAddArgs { /// Where to create the new workspace @@ -167,7 +171,20 @@ fn cmd_workspace_add( .display() )?; + // Copy sparse patterns from workspace where the command was run let mut new_workspace_command = WorkspaceCommandHelper::new(ui, command, new_workspace, repo)?; + let (mut locked_ws, _wc_commit) = new_workspace_command.start_working_copy_mutation()?; + let sparse_patterns = old_workspace_command + .working_copy() + .sparse_patterns()? + .to_vec(); + locked_ws + .locked_wc() + .set_sparse_patterns(sparse_patterns) + .map_err(|err| internal_error_with_message("Failed to set sparse patterns", err))?; + let operation_id = locked_ws.locked_wc().old_operation_id().clone(); + locked_ws.finish(operation_id)?; + let mut tx = new_workspace_command.start_transaction(); // If no parent revisions are specified, create a working-copy commit based diff --git a/cli/tests/test_workspaces.rs b/cli/tests/test_workspaces.rs index d83df594e71..008eddbbad5 100644 --- a/cli/tests/test_workspaces.rs +++ b/cli/tests/test_workspaces.rs @@ -81,16 +81,15 @@ fn test_workspaces_sparse_patterns() { test_env.jj_cmd_ok(&ws1_path, &["sparse", "set", "--clear", "--add=foo"]); test_env.jj_cmd_ok(&ws1_path, &["workspace", "add", "../ws2"]); let stdout = test_env.jj_cmd_success(&ws2_path, &["sparse", "list"]); - // TODO: Should inherit the sparse patterns from ws1 insta::assert_snapshot!(stdout, @r###" - . + foo "###); test_env.jj_cmd_ok(&ws2_path, &["sparse", "set", "--add=bar"]); test_env.jj_cmd_ok(&ws2_path, &["workspace", "add", "../ws3"]); let stdout = test_env.jj_cmd_success(&ws3_path, &["sparse", "list"]); - // TODO: Should inherit the sparse patterns from ws2 insta::assert_snapshot!(stdout, @r###" - . + bar + foo "###); }