diff --git a/lib/src/commit_builder.rs b/lib/src/commit_builder.rs index 97d15f5f789..1d2b373693e 100644 --- a/lib/src/commit_builder.rs +++ b/lib/src/commit_builder.rs @@ -119,6 +119,14 @@ impl CommitBuilder<'_> { self } + pub fn apply_if Self>(self, condition: bool, f: F) -> Self { + if condition { + f(self) + } else { + self + } + } + pub fn write(self) -> BackendResult { let mut rewrite_source_id = None; if let Some(rewrite_source) = self.rewrite_source { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3a24e8367eb..978fb380c18 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -29,6 +29,7 @@ use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; use jujutsu_lib::backend::{CommitId, ObjectId, TreeValue}; use jujutsu_lib::commit::Commit; +use jujutsu_lib::commit_builder::CommitBuilder; use jujutsu_lib::dag_walk::topo_order_reverse; use jujutsu_lib::index::IndexEntry; use jujutsu_lib::matchers::{EverythingMatcher, NothingMatcher}; @@ -2638,6 +2639,7 @@ don't make any changes, then the operation will be aborted. .mut_repo() .rewrite_commit(command.settings(), &commit) .set_tree(tree_id) + .apply_if(args.empty_parent, CommitBuilder::generate_new_change_id) .set_description(first_description) .write()?; let second_commit = tx @@ -2645,7 +2647,7 @@ don't make any changes, then the operation will be aborted. .rewrite_commit(command.settings(), &commit) .set_parents(vec![first_commit.id().clone()]) .set_tree(commit.tree_id().clone()) - .generate_new_change_id() + .apply_if(!args.empty_parent, CommitBuilder::generate_new_change_id) .set_description(second_description) .write()?; let mut rebaser = DescendantRebaser::new( diff --git a/tests/test_split_command.rs b/tests/test_split_command.rs index 78516d0d556..c5030916923 100644 --- a/tests/test_split_command.rs +++ b/tests/test_split_command.rs @@ -254,8 +254,8 @@ fn test_split_empty_parent() { @ d043564ef936 second original child | o ffdaa62087a2 first original child |/ - o 19b790168e73 target commit - o 8e4fac809cbb (empty) (no description set) + o 8e4fac809cbb target commit + o 19b790168e73 (empty) (no description set) o 9a45c67d3e96 original parent o 000000000000 (empty) (no description set) "###);