diff --git a/cli/tests/test_fix_command.rs b/cli/tests/test_fix_command.rs index 2b42948fe..e9a67e9bf 100644 --- a/cli/tests/test_fix_command.rs +++ b/cli/tests/test_fix_command.rs @@ -512,7 +512,7 @@ fn test_fix_resolve_conflict() { insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Fixed 3 commits of 3 checked. - Working copy now at: mzvwutvl 98dec555 (conflict) (no description set) + Working copy now at: mzvwutvl 669396ce (empty) (no description set) Parent commit : qpvuntsm 3c63716f a | (no description set) Parent commit : kkmpptxz 82703f5e b | (no description set) Added 0 files, modified 1 files, removed 0 files diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index 73e2c7e50..2ddb55ce9 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -1197,7 +1197,14 @@ impl MergedTreeBuilder { MergedTreeId::Merge(base_tree_ids) => base_tree_ids, }; let new_tree_ids = self.write_merged_trees(base_tree_ids, store)?; - Ok(MergedTreeId::Merge(new_tree_ids.simplify())) + match new_tree_ids.simplify().into_resolved() { + Ok(single_tree_id) => Ok(MergedTreeId::resolved(single_tree_id)), + Err(tree_id) => { + let tree = store.get_root_tree(&MergedTreeId::Merge(tree_id))?; + let resolved = tree.resolve()?; + Ok(resolved.id()) + } + } } fn write_merged_trees( diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 36e940530..03a05a7f5 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -23,7 +23,7 @@ use jj_lib::merged_tree::{ MergedTree, MergedTreeBuilder, MergedTreeVal, TreeDiffIterator, TreeDiffStreamImpl, }; use jj_lib::repo::Repo; -use jj_lib::repo_path::{RepoPath, RepoPathComponent}; +use jj_lib::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent}; use jj_lib::tree::merge_trees; use pretty_assertions::assert_eq; use testutils::{create_single_tree, write_file, TestRepo}; @@ -245,6 +245,28 @@ fn test_from_legacy_tree() { assert_eq!(recreated_merged_id, merged_tree.id()); } +/// Test that a tree built with no changes on top of an add/add conflict gets +/// resolved. +#[test] +fn test_merged_tree_builder_resolves_conflict() { + let test_repo = TestRepo::init(); + let repo = &test_repo.repo; + let store = repo.store(); + + let path1 = RepoPathBuf::from_internal_string("dir/file"); + let tree1 = create_single_tree(repo, &[(&path1, "foo")]); + let tree2 = create_single_tree(repo, &[(&path1, "bar")]); + let tree3 = create_single_tree(repo, &[(&path1, "bar")]); + + let base_tree_id = MergedTreeId::Merge(Merge::from_removes_adds( + [tree1.id().clone()], + [tree2.id().clone(), tree3.id().clone()], + )); + let tree_builder = MergedTreeBuilder::new(base_tree_id); + let tree_id = tree_builder.write_tree(store).unwrap(); + assert_eq!(tree_id, MergedTreeId::resolved(tree2.id().clone())); +} + #[test] fn test_path_value_and_entries() { let test_repo = TestRepo::init();