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

tests: leverage create_tree() in a few more tests

This commit is contained in:
Martin von Zweigbergk 2023-08-30 08:49:32 -07:00 committed by Martin von Zweigbergk
parent 26581750fe
commit 9d9b2cd057
2 changed files with 4 additions and 18 deletions

View file

@ -804,22 +804,12 @@ fn test_existing_directory_symlink(use_git: bool) {
// Creates a symlink in working directory, and a tree that will add a file under
// the symlinked directory.
std::os::unix::fs::symlink("..", workspace_root.join("parent")).unwrap();
let mut tree_builder = repo
.store()
.tree_builder(repo.store().empty_tree_id().clone());
testutils::write_normal_file(
&mut tree_builder,
&RepoPath::from_internal_string("parent/escaped"),
"contents",
);
let tree_id = tree_builder.write_tree();
let tree = repo.store().get_tree(&RepoPath::root(), &tree_id).unwrap();
let file_path = RepoPath::from_internal_string("parent/escaped");
let tree = create_tree(repo, &[(&file_path, "contents")]);
// Checkout should fail because "parent" already exists and is a symlink.
let wc = test_workspace.workspace.working_copy_mut();
assert!(wc
.check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree))
.is_err());
assert!(wc.check_out(repo.op_id().clone(), None, &tree).is_err());
// Therefore, "../escaped" shouldn't be created.
assert!(!workspace_root.parent().unwrap().join("escaped").exists());

View file

@ -261,13 +261,9 @@ pub fn create_tree(repo: &Arc<ReadonlyRepo>, path_contents: &[(&RepoPath, &str)]
#[must_use]
pub fn create_random_tree(repo: &Arc<ReadonlyRepo>) -> MergedTreeId {
let mut tree_builder = repo
.store()
.tree_builder(repo.store().empty_tree_id().clone());
let number = rand::random::<u32>();
let path = RepoPath::from_internal_string(format!("file{number}").as_str());
write_normal_file(&mut tree_builder, &path, "contents");
MergedTreeId::Legacy(tree_builder.write_tree())
create_tree(repo, &[(&path, "contents")]).id()
}
pub fn create_random_commit<'repo>(