From 6be2d1bd72a69922941d7986b1e0b996548b55bc Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 17 Sep 2023 23:33:29 -0700 Subject: [PATCH] merged_tree: use child path when merging child This fixes a bug where we used the parent directory's path when trying read trees and files for a child entry. Many tests in `test_merged_tree` fail after switching to the test backend there without this fix/ --- lib/src/merged_tree.rs | 3 ++- lib/tests/test_merged_tree.rs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index d4c250c05e..45ee8071cd 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -418,7 +418,8 @@ fn merge_trees(merge: &Merge) -> Result, TreeMergeError> { let mut conflicts = vec![]; for basename in all_tree_conflict_names(merge) { let path_merge = merge.map(|tree| tree.value(basename).cloned()); - let path_merge = merge_tree_values(store, dir, path_merge)?; + let path = dir.join(basename); + let path_merge = merge_tree_values(store, &path, path_merge)?; match path_merge.into_resolved() { Ok(value) => { new_tree.set_or_remove(basename, value); diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 07a33ac752..a8941ca4a0 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -32,7 +32,7 @@ fn file_value(file_id: &FileId) -> TreeValue { #[test] fn test_from_legacy_tree() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let store = repo.store(); @@ -223,7 +223,7 @@ fn test_from_legacy_tree() { #[test] fn test_path_value_and_entries() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // Create a MergedTree @@ -348,7 +348,7 @@ fn test_path_value_and_entries() { #[test] fn test_resolve_success() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let unchanged_path = RepoPath::from_internal_string("unchanged"); @@ -415,7 +415,7 @@ fn test_resolve_success() { #[test] fn test_resolve_root_becomes_empty() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let store = repo.store(); @@ -432,7 +432,7 @@ fn test_resolve_root_becomes_empty() { #[test] fn test_resolve_with_conflict() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // The trivial conflict should be resolved but the non-trivial should not (and @@ -459,7 +459,7 @@ fn test_resolve_with_conflict() { #[test] fn test_conflict_iterator() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let unchanged_path = RepoPath::from_internal_string("dir/subdir/unchanged"); @@ -575,7 +575,7 @@ fn test_conflict_iterator() { } #[test] fn test_conflict_iterator_higher_arity() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let two_sided_path = RepoPath::from_internal_string("dir/2-sided"); @@ -652,7 +652,7 @@ fn test_conflict_iterator_higher_arity() { /// Diff two resolved trees #[test] fn test_diff_resolved() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let clean_path = RepoPath::from_internal_string("dir1/file"); @@ -711,7 +711,7 @@ fn test_diff_resolved() { /// Diff two conflicted trees #[test] fn test_diff_conflicted() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // path1 is a clean (unchanged) conflict @@ -816,7 +816,7 @@ fn test_diff_conflicted() { #[test] fn test_diff_dir_file() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // path1: file1 -> directory1 @@ -1048,7 +1048,7 @@ fn test_diff_dir_file() { /// Merge 3 resolved trees that can be resolved #[test] fn test_merge_simple() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let path1 = RepoPath::from_internal_string("dir1/file"); @@ -1069,7 +1069,7 @@ fn test_merge_simple() { /// Merge 3 resolved trees that can be partially resolved #[test] fn test_merge_partial_resolution() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // path1 can be resolved, path2 cannot @@ -1096,7 +1096,7 @@ fn test_merge_partial_resolution() { /// Merge 3 resolved trees, including one empty legacy tree #[test] fn test_merge_with_empty_legacy_tree() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let path1 = RepoPath::from_internal_string("dir1/file"); @@ -1121,7 +1121,7 @@ fn test_merge_with_empty_legacy_tree() { /// at by only simplifying the conflict (no need to recurse) #[test] fn test_merge_simplify_only() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; let path = RepoPath::from_internal_string("dir1/file"); @@ -1154,7 +1154,7 @@ fn test_merge_simplify_only() { /// result is a 3-way conflict. #[test] fn test_merge_simplify_result() { - let test_repo = TestRepo::init_with_backend(TestRepoBackend::Git); + let test_repo = TestRepo::init_with_backend(TestRepoBackend::Test); let repo = &test_repo.repo; // The conflict in path1 cannot be resolved, but the conflict in path2 can.