local_working_copy: migrate Git submodule test to MergedTreeBuilder

I also removed tx.commit() because the test doesn't rely on the committed
operation.
This commit is contained in:
Yuya Nishihara 2024-11-11 10:38:12 +09:00
parent 1aad724798
commit 4983db563f

View file

@ -1160,7 +1160,7 @@ fn test_dotgit_ignored() {
} }
#[test] #[test]
fn test_gitsubmodule() { fn test_git_submodule() {
// Tests that git submodules are ignored. // Tests that git submodules are ignored.
let settings = testutils::user_settings(); let settings = testutils::user_settings();
@ -1168,33 +1168,30 @@ fn test_gitsubmodule() {
let repo = &test_workspace.repo; let repo = &test_workspace.repo;
let store = repo.store().clone(); let store = repo.store().clone();
let workspace_root = test_workspace.workspace.workspace_root().to_owned(); let workspace_root = test_workspace.workspace.workspace_root().to_owned();
let mut tx = repo.start_transaction(&settings);
let mut tree_builder = store.tree_builder(store.empty_tree_id().clone());
let added_path = RepoPath::from_internal_string("added"); let added_path = RepoPath::from_internal_string("added");
let submodule_path = RepoPath::from_internal_string("submodule"); let submodule_path = RepoPath::from_internal_string("submodule");
let added_submodule_path = RepoPath::from_internal_string("submodule/added"); 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(), added_path.to_owned(),
TreeValue::File { Merge::normal(TreeValue::File {
id: testutils::write_file(repo.store(), added_path, "added\n"), id: testutils::write_file(repo.store(), added_path, "added\n"),
executable: false, executable: false,
}, }),
); );
let mut tx = repo.start_transaction(&settings);
let submodule_id = write_random_commit(tx.repo_mut(), &settings).id().clone(); 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(), 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_id = tree_builder.write_tree(&store).unwrap();
let tree = store.get_root_tree(&tree_id).unwrap(); let commit = commit_with_tree(repo.store(), tree_id.clone());
let commit = commit_with_tree(repo.store(), tree.id());
let ws = &mut test_workspace.workspace; let ws = &mut test_workspace.workspace;
ws.check_out(repo.op_id().clone(), None, &commit).unwrap(); ws.check_out(repo.op_id().clone(), None, &commit).unwrap();