Skip to content

Commit f38c59f

Browse files
committed
split: do not prevent all changes from going into the first commit
Let the user select all changes interactively and put them into the first commit, and create a second commit with the possibility of preserving the current commit message. This was previously only possible in non-interactive mode by specifying matching paths, e.g. ".". In both cases, a warning will be issued indicating that the second commit is empty.
1 parent 98c16c4 commit f38c59f

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9191
* `jj git fetch -b <remote-git-branch-name>` will now warn if the branch(es)
9292
can not be found in any of the specified/configured remotes.
9393

94+
* `jj split` now lets the user select all changes in interactive mode. This may be used
95+
to keeping all changes into the first commit while keeping the current commit
96+
description for the second commit (the newly created empty one).
97+
9498
### Fixed bugs
9599

96100
* Update working copy before reporting changes. This prevents errors during reporting

cli/src/commands/split.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ You are splitting a commit into two: {}
9999
The diff initially shows the changes in the commit you're splitting.
100100
101101
Adjust the right side until it shows the contents you want for the first commit.
102-
The remainder will be in the second commit. If you don't make any changes, then
103-
the operation will be aborted.
102+
The remainder will be in the second commit.
104103
",
105104
tx.format_commit_summary(&commit)
106105
)
@@ -109,12 +108,13 @@ the operation will be aborted.
109108
// Prompt the user to select the changes they want for the first commit.
110109
let selected_tree_id =
111110
diff_selector.select(&base_tree, &end_tree, matcher.as_ref(), format_instructions)?;
112-
if &selected_tree_id == commit.tree_id() && diff_selector.is_interactive() {
111+
if &selected_tree_id == commit.tree_id() {
113112
// The user selected everything from the original commit.
114-
writeln!(ui.status(), "Nothing changed.")?;
115-
return Ok(());
116-
}
117-
if selected_tree_id == base_tree.id() {
113+
writeln!(
114+
ui.warning_default(),
115+
"All changes have been selected, so the second commit will be empty"
116+
)?;
117+
} else if selected_tree_id == base_tree.id() {
118118
// The user selected nothing, so the first commit will be empty.
119119
writeln!(
120120
ui.warning_default(),

cli/tests/test_split_command.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ fn test_split_by_paths() {
102102
test_env.set_up_fake_editor();
103103
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["split", "-r", "@-", "."]);
104104
insta::assert_snapshot!(stdout, @"");
105-
insta::assert_snapshot!(stderr, @r###"
105+
insta::assert_snapshot!(stderr, @r#"
106+
Warning: All changes have been selected, so the second commit will be empty
106107
Rebased 1 descendant commits
107108
First part: qpvuntsm 9da0eea0 (no description set)
108109
Second part: znkkpsqq 5b5714a3 (empty) (no description set)
109110
Working copy now at: zsuskuln 0c798ee7 (no description set)
110111
Parent commit : znkkpsqq 5b5714a3 (empty) (no description set)
111-
"###);
112+
"#);
112113

113114
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
114115
@ zsuskulnrvyr false
@@ -576,15 +577,14 @@ fn test_split_interactive() {
576577
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_path, &["split"]);
577578

578579
insta::assert_snapshot!(
579-
std::fs::read_to_string(test_env.env_root().join("instrs")).unwrap(), @r###"
580+
std::fs::read_to_string(test_env.env_root().join("instrs")).unwrap(), @r#"
580581
You are splitting a commit into two: qpvuntsm 44af2155 (no description set)
581582
582583
The diff initially shows the changes in the commit you're splitting.
583584
584585
Adjust the right side until it shows the contents you want for the first commit.
585-
The remainder will be in the second commit. If you don't make any changes, then
586-
the operation will be aborted.
587-
"###);
586+
The remainder will be in the second commit.
587+
"#);
588588

589589
insta::assert_snapshot!(
590590
std::fs::read_to_string(test_env.env_root().join("editor")).unwrap(), @r###"

0 commit comments

Comments
 (0)