Skip to content

Commit

Permalink
split: do not prevent all changes from going into the first commit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samueltardieu committed Sep 26, 2024
1 parent 7727961 commit 30a0235
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ 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 git fetch -b <remote-git-branch-name>` will now warn if the branch(es)
can not be found in any of the specified/configured remotes.

* `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

* Update working copy before reporting changes. This prevents errors during reporting
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 @@ -99,8 +99,7 @@ You are splitting a commit into two: {}
The diff initially shows the changes in the commit you're splitting.
Adjust the right side until it shows the contents you want for the first commit.
The remainder will be in the second commit. If you don't make any changes, then
the operation will be aborted.
The remainder will be in the second commit.
",
tx.format_commit_summary(&commit)
)
Expand All @@ -109,12 +108,13 @@ 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(),
Expand Down
12 changes: 6 additions & 6 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 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
Expand Down Expand Up @@ -576,15 +577,14 @@ fn test_split_interactive() {
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_path, &["split"]);

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

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

0 comments on commit 30a0235

Please sign in to comment.