Skip to content

Commit

Permalink
split: keep change id with child if --empty-parent is used
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Jan 31, 2023
1 parent aa26480 commit 60d05e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/src/commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ impl CommitBuilder<'_> {
self
}

pub fn apply_if<F: FnOnce(Self) -> Self>(self, condition: bool, f: F) -> Self {
if condition {
f(self)
} else {
self
}
}

pub fn write(self) -> BackendResult<Commit> {
let mut rewrite_source_id = None;
if let Some(rewrite_source) = self.rewrite_source {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -2638,14 +2639,15 @@ 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
.mut_repo()
.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(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_split_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"###);
Expand Down

0 comments on commit 60d05e4

Please sign in to comment.