cli: make new workspace inherit sparse pattern from old workspace

This commit is contained in:
Martin von Zweigbergk 2024-02-17 09:04:21 -08:00 committed by Martin von Zweigbergk
parent 6d7affc4da
commit 866e862ab0
4 changed files with 27 additions and 4 deletions

View file

@ -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

View file

@ -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 `@<workspace name>` 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

View file

@ -1888,6 +1888,8 @@ Workspaces let you add additional working copies attached to the same repo. A co
Each workspace has its own working-copy commit. When you have more than one workspace attached to a repo, they are indicated by `@<workspace name>` in `jj log`.
Each workspace also has own sparse patterns.
**Usage:** `jj workspace <COMMAND>`
###### **Subcommands:**
@ -1904,6 +1906,8 @@ Each workspace has its own working-copy commit. When you have more than one work
Add a workspace
Sparse patterns will be copied over from the current workspace.
**Usage:** `jj workspace add [OPTIONS] <DESTINATION>`
###### **Arguments:**

View file

@ -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
"###);
}