From fc59db5d52139b048f38c632b062fd502ca4a06d Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 29 Jan 2023 07:35:41 +0100 Subject: [PATCH] split: allow creation of empty parent or child jj split . => create an empty child jj split nonexistent => create an empty parent --- CHANGELOG.md | 5 ++++ src/commands/mod.rs | 5 ++-- tests/test_split_command.rs | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6005eeb..f6bfa988f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Commands that draw an ASCII graph (`jj log`, `jj op log`, `jj obslog`) now have different styles available by setting e.g. `ui.graph.style = "curved"`. +* `jj split` accepts creating empty commits when given a path. `jj split .` + inserts an empty commit between the target commit and its children if any, + and `jj split any-non-existent-path` inserts an empty commit between the + target commit and its parents. + ### Fixed bugs * When sharing the working copy with a Git repo, we used to forget to export diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 13c5fb2f1..74702aa02 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2557,6 +2557,7 @@ fn cmd_split(ui: &mut Ui, command: &CommandHelper, args: &SplitArgs) -> Result<( let mut tx = workspace_command.start_transaction(&format!("split commit {}", commit.id().hex())); let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), &commit.parents()); + let interactive = args.paths.is_empty(); let instructions = format!( "\ You are splitting a commit in two: {} @@ -2574,10 +2575,10 @@ don't make any changes, then the operation will be aborted. &base_tree, &commit.tree(), &instructions, - args.paths.is_empty(), + interactive, matcher.as_ref(), )?; - if &tree_id == commit.tree_id() { + if &tree_id == commit.tree_id() && interactive { ui.write("Nothing changed.\n")?; } else { let middle_tree = tx diff --git a/tests/test_split_command.rs b/tests/test_split_command.rs index 614f0378f..82190bdfc 100644 --- a/tests/test_split_command.rs +++ b/tests/test_split_command.rs @@ -80,4 +80,55 @@ fn test_split_by_paths() { A file1 A file3 "###); + + // Insert an empty commit after @- with "split ." + test_env.set_up_fake_editor(); + let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "."]); + insta::assert_snapshot!(stdout, @r###" + Rebased 1 descendant commits + First part: 31425b568fcf (no description set) + Second part: af0963926ac3 (no description set) + Working copy now at: 28d4ec20efa9 (no description set) + "###); + + let stdout = + test_env.jj_cmd_success(&repo_path, &["log", "-T", r#"change_id.short() " " empty"#]); + insta::assert_snapshot!(stdout, @r###" + @ ffdaa62087a2 false + o 19b790168e73 true + o 9a45c67d3e96 false + o 000000000000 true + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@--"]); + insta::assert_snapshot!(stdout, @r###" + A file2 + "###); + + // Remove newly created empty commit + test_env.jj_cmd_success(&repo_path, &["abandon", "@-"]); + + // Insert an empty commit before @- with "split nonexistent" + test_env.set_up_fake_editor(); + let stdout = test_env.jj_cmd_success(&repo_path, &["split", "-r", "@-", "nonexistent"]); + insta::assert_snapshot!(stdout, @r###" + Rebased 1 descendant commits + First part: 0647b2cbd0da (no description set) + Second part: d5d77af65446 (no description set) + Working copy now at: 86f228dc3a50 (no description set) + "###); + + let stdout = + test_env.jj_cmd_success(&repo_path, &["log", "-T", r#"change_id.short() " " empty"#]); + insta::assert_snapshot!(stdout, @r###" + @ ffdaa62087a2 false + o fa9213bcf78e false + o 9a45c67d3e96 true + o 000000000000 true + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@-"]); + insta::assert_snapshot!(stdout, @r###" + A file2 + "###); }