ok/jj
1
0
Fork 0
forked from mirrors/jj

merged_tree: make tree builder attempt to resolve conflicts

As we discovered in the `jj fix` tests,
`MergedTreeBuilder::write_tree()` doesn't try to resolve conflicts,
not even trivial ones. This patch fixes that.
This commit is contained in:
Martin von Zweigbergk 2024-05-31 14:41:12 -07:00 committed by Martin von Zweigbergk
parent 2e6a0f9e96
commit 65a988e3d2
3 changed files with 32 additions and 3 deletions

View file

@ -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

View file

@ -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(

View file

@ -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();