From 4983db563ff1afd9f02907058b60bb9f8cd0c6cf Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 11 Nov 2024 10:38:12 +0900 Subject: [PATCH] local_working_copy: migrate Git submodule test to MergedTreeBuilder I also removed tx.commit() because the test doesn't rely on the committed operation. --- lib/tests/test_local_working_copy.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/tests/test_local_working_copy.rs b/lib/tests/test_local_working_copy.rs index 9ecddd711b..9ef10a6bb4 100644 --- a/lib/tests/test_local_working_copy.rs +++ b/lib/tests/test_local_working_copy.rs @@ -1160,7 +1160,7 @@ fn test_dotgit_ignored() { } #[test] -fn test_gitsubmodule() { +fn test_git_submodule() { // Tests that git submodules are ignored. let settings = testutils::user_settings(); @@ -1168,33 +1168,30 @@ fn test_gitsubmodule() { let repo = &test_workspace.repo; let store = repo.store().clone(); let workspace_root = test_workspace.workspace.workspace_root().to_owned(); - - let mut tree_builder = store.tree_builder(store.empty_tree_id().clone()); + let mut tx = repo.start_transaction(&settings); let added_path = RepoPath::from_internal_string("added"); let submodule_path = RepoPath::from_internal_string("submodule"); let added_submodule_path = RepoPath::from_internal_string("submodule/added"); - tree_builder.set( + let mut tree_builder = MergedTreeBuilder::new(store.empty_merged_tree_id()); + tree_builder.set_or_remove( added_path.to_owned(), - TreeValue::File { + Merge::normal(TreeValue::File { id: testutils::write_file(repo.store(), added_path, "added\n"), executable: false, - }, + }), ); - let mut tx = repo.start_transaction(&settings); let submodule_id = write_random_commit(tx.repo_mut(), &settings).id().clone(); - tx.commit("create submodule commit"); - tree_builder.set( + tree_builder.set_or_remove( submodule_path.to_owned(), - TreeValue::GitSubmodule(submodule_id), + Merge::normal(TreeValue::GitSubmodule(submodule_id)), ); - let tree_id = MergedTreeId::Legacy(tree_builder.write_tree().unwrap()); - let tree = store.get_root_tree(&tree_id).unwrap(); - let commit = commit_with_tree(repo.store(), tree.id()); + let tree_id = tree_builder.write_tree(&store).unwrap(); + let commit = commit_with_tree(repo.store(), tree_id.clone()); let ws = &mut test_workspace.workspace; ws.check_out(repo.op_id().clone(), None, &commit).unwrap();