diff --git a/CHANGELOG.md b/CHANGELOG.md index ebbf78ef4..4d38ecc2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The `git_head` template keyword now returns an optional value instead of a list of 0 or 1 element. +* The `jj sparse set --edit` was split up into `jj sparse edit`. + * The `jj sparse` subcommands now parse and print patterns as workspace-relative paths. diff --git a/cli/src/commands/sparse.rs b/cli/src/commands/sparse.rs index edd014567..4a2e10784 100644 --- a/cli/src/commands/sparse.rs +++ b/cli/src/commands/sparse.rs @@ -37,6 +37,7 @@ use crate::ui::Ui; pub(crate) enum SparseArgs { List(SparseListArgs), Set(SparseSetArgs), + Edit(SparseEditArgs), } /// List the patterns that are currently present in the working copy @@ -72,14 +73,15 @@ pub(crate) struct SparseSetArgs { /// Include no files in the working copy (combine with --add) #[arg(long)] clear: bool, - /// Edit patterns with $EDITOR - #[arg(long)] - edit: bool, /// Include all files in the working copy #[arg(long, conflicts_with_all = &["add", "remove", "clear"])] reset: bool, } +/// Start an editor to update the patterns that are present in the working copy +#[derive(clap::Args, Clone, Debug)] +pub(crate) struct SparseEditArgs {} + #[instrument(skip_all)] pub(crate) fn cmd_sparse( ui: &mut Ui, @@ -89,6 +91,7 @@ pub(crate) fn cmd_sparse( match args { SparseArgs::List(sub_args) => cmd_sparse_list(ui, command, sub_args), SparseArgs::Set(sub_args) => cmd_sparse_set(ui, command, sub_args), + SparseArgs::Edit(sub_args) => cmd_sparse_edit(ui, command, sub_args), } } @@ -112,7 +115,6 @@ fn cmd_sparse_set( args: &SparseSetArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let repo_path = workspace_command.repo().repo_path().to_owned(); update_sparse_patterns_with(ui, &mut workspace_command, |_ui, old_patterns| { let mut new_patterns = HashSet::new(); if args.reset { @@ -128,12 +130,21 @@ fn cmd_sparse_set( new_patterns.insert(path.to_owned()); } } - let mut new_patterns = new_patterns.into_iter().collect_vec(); - new_patterns.sort(); - if args.edit { - new_patterns = edit_sparse(&repo_path, &new_patterns, command.settings())?; - new_patterns.sort(); - } + Ok(new_patterns.into_iter().sorted_unstable().collect()) + }) +} + +#[instrument(skip_all)] +fn cmd_sparse_edit( + ui: &mut Ui, + command: &CommandHelper, + _args: &SparseEditArgs, +) -> Result<(), CommandError> { + let mut workspace_command = command.workspace_helper(ui)?; + let repo_path = workspace_command.repo().repo_path().to_owned(); + update_sparse_patterns_with(ui, &mut workspace_command, |_ui, old_patterns| { + let mut new_patterns = edit_sparse(&repo_path, old_patterns, command.settings())?; + new_patterns.sort_unstable(); Ok(new_patterns) }) } diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 52f219429..78ce17806 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -70,6 +70,7 @@ This document contains the help content for the `jj` command-line program. * [`jj sparse`↴](#jj-sparse) * [`jj sparse list`↴](#jj-sparse-list) * [`jj sparse set`↴](#jj-sparse-set) +* [`jj sparse edit`↴](#jj-sparse-edit) * [`jj split`↴](#jj-split) * [`jj squash`↴](#jj-squash) * [`jj status`↴](#jj-status) @@ -1614,6 +1615,7 @@ Manage which paths from the working-copy commit are present in the working copy * `list` — List the patterns that are currently present in the working copy * `set` — Update the patterns that are present in the working copy +* `edit` — Start an editor to update the patterns that are present in the working copy @@ -1643,10 +1645,6 @@ For example, if all you need is the `README.md` and the `lib/` directory, use `j Possible values: `true`, `false` -* `--edit` — Edit patterns with $EDITOR - - Possible values: `true`, `false` - * `--reset` — Include all files in the working copy Possible values: `true`, `false` @@ -1654,6 +1652,14 @@ For example, if all you need is the `README.md` and the `lib/` directory, use `j +## `jj sparse edit` + +Start an editor to update the patterns that are present in the working copy + +**Usage:** `jj sparse edit` + + + ## `jj split` Split a revision in two diff --git a/cli/tests/test_sparse_command.rs b/cli/tests/test_sparse_command.rs index f641a4e18..c62f65007 100644 --- a/cli/tests/test_sparse_command.rs +++ b/cli/tests/test_sparse_command.rs @@ -147,7 +147,7 @@ fn test_sparse_manage_patterns() { let read_patterns = || std::fs::read_to_string(test_env.env_root().join("patterns0")).unwrap(); edit_patterns(&["file1"]); - let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "set", "--edit"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "edit"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Added 0 files, modified 0 files, removed 2 files @@ -158,30 +158,16 @@ fn test_sparse_manage_patterns() { file1 "###); - // Can edit with `--clear` and `--add` - edit_patterns(&["file2"]); - let (stdout, stderr) = test_env.jj_cmd_ok( - &sub_dir, - &["sparse", "set", "--edit", "--clear", "--add", "file1"], - ); - insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Added 1 files, modified 0 files, removed 1 files - "###); - insta::assert_snapshot!(read_patterns(), @"file1"); - let stdout = test_env.jj_cmd_success(&sub_dir, &["sparse", "list"]); - insta::assert_snapshot!(stdout, @r###" - file2 - "###); - // Can edit with multiple files - edit_patterns(&["file2", "file3"]); - let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "set", "--clear", "--edit"]); + edit_patterns(&["file3", "file2"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "edit"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - Added 1 files, modified 0 files, removed 0 files + Added 2 files, modified 0 files, removed 1 files + "###); + insta::assert_snapshot!(read_patterns(), @r###" + file1 "###); - insta::assert_snapshot!(read_patterns(), @""); let stdout = test_env.jj_cmd_success(&sub_dir, &["sparse", "list"]); insta::assert_snapshot!(stdout, @r###" file2