Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split: do not prevent all changes from going into the parent commit, and a fix #4542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* `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
17 changes: 8 additions & 9 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,17 +108,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.
samueltardieu marked this conversation as resolved.
Show resolved Hide resolved
writeln!(ui.status(), "Nothing changed.")?;
return Ok(());
}
if selected_tree_id == base_tree.id() {
writeln!(
ui.warning_default(),
"All changes have been selected, so 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, so the first commit will be empty"
)?;
}

Expand Down
18 changes: 9 additions & 9 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, so 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 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, so 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
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