Skip to content

Commit

Permalink
split: do not prevent all changes from going into the parent commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Sep 26, 2024
1 parent bd82ab3 commit 10409f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 move all changes into a parent commit while preserving the current commit
description.

### Fixed bugs

Expand Down
14 changes: 7 additions & 7 deletions cli/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 child 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 parent commit will be empty"
)?;
}

Expand Down
11 changes: 6 additions & 5 deletions cli/tests/test_split_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 child 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
Expand All @@ -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 parent 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
Expand Down

0 comments on commit 10409f6

Please sign in to comment.