Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make new workspace inherit sparse patterns #3079

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cli/src/commands/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand All @@ -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:**
Expand Down
24 changes: 24 additions & 0 deletions cli/tests/test_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ fn test_workspaces_add_second_workspace() {
"###);
}

/// Test how sparse patterns are inherited
#[test]
fn test_workspaces_sparse_patterns() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "--git", "ws1"]);
let ws1_path = test_env.env_root().join("ws1");
let ws2_path = test_env.env_root().join("ws2");
let ws3_path = test_env.env_root().join("ws3");

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"]);
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"]);
insta::assert_snapshot!(stdout, @r###"
bar
foo
"###);
}

/// Test adding a second workspace while the current workspace is editing a
/// merge
#[test]
Expand Down