From cc8d65cb86c9034ecf716c963c60e5355dd0a100 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu <sam@rfc1149.net> Date: Thu, 26 Sep 2024 18:22:54 +0200 Subject: [PATCH] split: do not prevent all changes from going into the parent commit --- CHANGELOG.md | 7 +++++++ cli/src/commands/split.rs | 14 +++++++------- cli/tests/test_split_command.rs | 11 ++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ddfbc5d62..ec72dec2566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * `jj diffedit`, `jj abandon`, and `jj restore` now accept a `--restore-descendants` flag. When used, descendants of the edited or deleted commits will keep their original content. + +* `jj split` now lets the user select all changes in interactive mode. This may be used + to keeping all changes into the first commit while keeping the current commit + description for the second commit (the newly created empty one). ### Fixed bugs @@ -100,6 +104,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ([#2611](https://github.com/martinvonz/jj/pull/2611)) * Editing a hidden commit now makes it visible. + + * `jj split` will no longer reference the paths given on the command line when + none have been given in interactive mode. ## [0.21.0] - 2024-09-04 diff --git a/cli/src/commands/split.rs b/cli/src/commands/split.rs index 496172dac67..0b10fa56009 100644 --- a/cli/src/commands/split.rs +++ b/cli/src/commands/split.rs @@ -109,17 +109,17 @@ the operation will be aborted. // Prompt the user to select the changes they want for the first commit. let selected_tree_id = diff_selector.select(&base_tree, &end_tree, matcher.as_ref(), format_instructions)?; - if &selected_tree_id == commit.tree_id() && diff_selector.is_interactive() { + if &selected_tree_id == commit.tree_id() { // The user selected everything from the original commit. - writeln!(ui.status(), "Nothing changed.")?; - return Ok(()); - } - if selected_tree_id == base_tree.id() { + writeln!( + ui.warning_default(), + "All changes have been selected, the second commit will be empty" + )?; + } else if selected_tree_id == base_tree.id() { // The user selected nothing, so the first commit will be empty. writeln!( ui.warning_default(), - "The given paths do not match any file: {}", - args.paths.join(" ") + "No changes have been selected, the first commit will be empty" )?; } diff --git a/cli/tests/test_split_command.rs b/cli/tests/test_split_command.rs index 376a53844fc..9bc4ccd8eac 100644 --- a/cli/tests/test_split_command.rs +++ b/cli/tests/test_split_command.rs @@ -102,13 +102,14 @@ fn test_split_by_paths() { test_env.set_up_fake_editor(); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "-r", "@-", "."]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" + insta::assert_snapshot!(stderr, @r#" + Warning: All changes have been selected, the second commit will be empty Rebased 1 descendant commits First part: qpvuntsm 9da0eea0 (no description set) Second part: znkkpsqq 5b5714a3 (empty) (no description set) Working copy now at: zsuskuln 0c798ee7 (no description set) Parent commit : znkkpsqq 5b5714a3 (empty) (no description set) - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ zsuskulnrvyr false @@ -129,14 +130,14 @@ fn test_split_by_paths() { test_env.set_up_fake_editor(); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "-r", "@-", "nonexistent"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @r###" - Warning: The given paths do not match any file: nonexistent + insta::assert_snapshot!(stderr, @r#" + Warning: No changes have been selected, the first commit will be empty Rebased 1 descendant commits First part: qpvuntsm bd42f95a (empty) (no description set) Second part: lylxulpl ed55c86b (no description set) Working copy now at: zsuskuln 1e1ed741 (no description set) Parent commit : lylxulpl ed55c86b (no description set) - "###); + "#); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" @ zsuskulnrvyr false