transaction: when checking out open commit with conflicts, create child commit

I've been confused twice that rebasing an open commit so it results in
conflicts doesn't show the conflicts in the log output. That's because
we create a successor instead if a commit with conflicts is open. I
guess I thought it would be expected that a child commit was not
created. Since it seems surprising in practice, let's change it and
we'll see if the new behavior is more or less surprising.
This commit is contained in:
Martin von Zweigbergk 2021-01-21 22:11:03 -08:00
parent bb730d8a2b
commit 9ffd35caf8
2 changed files with 6 additions and 14 deletions

View file

@ -123,8 +123,9 @@ impl<'r> Transaction<'r> {
}
let tree_id = tree_builder.write_tree();
let open_commit;
if !commit.is_open() {
// If the commit is closed, create a new open commit on top
if !commit.is_open() || &tree_id != commit.tree().id() {
// If the commit is closed, or if it had conflicts, create a new open commit on
// top
open_commit = CommitBuilder::for_open_commit(
settings,
self.store(),
@ -132,12 +133,6 @@ impl<'r> Transaction<'r> {
tree_id,
)
.write_to_transaction(self);
} else if &tree_id != commit.tree().id() {
// If the commit is open but had conflicts, create a successor with the
// conflicts materialized.
open_commit = CommitBuilder::for_rewrite_from(settings, self.store(), commit)
.set_tree(tree_id)
.write_to_transaction(self);
} else {
// Otherwise the commit was open and didn't have any conflicts, so just use
// that commit as is.

View file

@ -74,7 +74,7 @@ fn test_checkout_closed(use_git: bool) {
#[test_case(false ; "local store")]
// #[test_case(true ; "git store")]
fn test_checkout_open_with_conflict(use_git: bool) {
// Test that Transaction::check_out() creates a successor if the requested
// Test that Transaction::check_out() creates a child if the requested
// commit is open and has conflicts
let settings = testutils::user_settings();
let (_temp_dir, mut repo) = testutils::init_repo(&settings, use_git);
@ -105,11 +105,8 @@ fn test_checkout_open_with_conflict(use_git: bool) {
}) => {}
_ => panic!("unexpected tree value: {:?}", file_value),
}
assert_eq!(actual_checkout.predecessors().len(), 1);
assert_eq!(
actual_checkout.predecessors()[0].id(),
requested_checkout.id()
);
assert_eq!(actual_checkout.parents().len(), 1);
assert_eq!(actual_checkout.parents()[0].id(), requested_checkout.id());
tx.commit();
Arc::get_mut(&mut repo).unwrap().reload();
assert_eq!(repo.view().checkout(), actual_checkout.id());