testutils: use .jj-internal git repos in most tests

I don't think there's much reason to run most tests with a `.git`
directory outside of `.jj`. I think it's just that way for historical
reasons. It's been that way since I added support for `.jj`-internal
repos in a8a9f7dedd.

The reason I want to switch is to make it a little easier to create
test repos for different backends. The problem with `.jj`-external git
repos is that they depend on an additional path.

I had to update `test_bad_locking.rs` to make the code merging
directories able handle missing directories on some side, because
git's loose objects result in directories getting created on one or
both sides.
This commit is contained in:
Martin von Zweigbergk 2023-09-17 09:41:14 -07:00 committed by Martin von Zweigbergk
parent 2bc641c57c
commit 79527d707c
2 changed files with 39 additions and 37 deletions

View file

@ -38,45 +38,51 @@ fn merge_directories(left: &Path, base: &Path, right: &Path, output: &Path) {
std::fs::create_dir(output).unwrap(); std::fs::create_dir(output).unwrap();
let mut sub_dirs = vec![]; let mut sub_dirs = vec![];
// Walk the left side and copy to the output // Walk the left side and copy to the output
for entry in std::fs::read_dir(left).unwrap() { if left.exists() {
let path = entry.unwrap().path(); for entry in std::fs::read_dir(left).unwrap() {
let base_name = path.file_name().unwrap(); let path = entry.unwrap().path();
let child_left = left.join(base_name); let base_name = path.file_name().unwrap();
let child_output = output.join(base_name); let child_left = left.join(base_name);
if child_left.is_dir() { let child_output = output.join(base_name);
sub_dirs.push(base_name.to_os_string()); if child_left.is_dir() {
} else { sub_dirs.push(base_name.to_os_string());
std::fs::copy(&child_left, child_output).unwrap(); } else {
std::fs::copy(&child_left, child_output).unwrap();
}
} }
} }
// Walk the base and find files removed in the right side, then remove them in // Walk the base and find files removed in the right side, then remove them in
// the output // the output
for entry in std::fs::read_dir(base).unwrap() { if base.exists() {
let path = entry.unwrap().path(); for entry in std::fs::read_dir(base).unwrap() {
let base_name = path.file_name().unwrap(); let path = entry.unwrap().path();
let child_base = base.join(base_name); let base_name = path.file_name().unwrap();
let child_right = right.join(base_name); let child_base = base.join(base_name);
let child_output = output.join(base_name); let child_right = right.join(base_name);
if child_base.is_dir() { let child_output = output.join(base_name);
sub_dirs.push(base_name.to_os_string()); if child_base.is_dir() {
} else if !child_right.exists() { sub_dirs.push(base_name.to_os_string());
std::fs::remove_file(child_output).ok(); } else if !child_right.exists() {
std::fs::remove_file(child_output).ok();
}
} }
} }
// Walk the right side and find files added in the right side, then add them in // Walk the right side and find files added in the right side, then add them in
// the output // the output
for entry in std::fs::read_dir(right).unwrap() { if right.exists() {
let path = entry.unwrap().path(); for entry in std::fs::read_dir(right).unwrap() {
let base_name = path.file_name().unwrap(); let path = entry.unwrap().path();
let child_base = base.join(base_name); let base_name = path.file_name().unwrap();
let child_right = right.join(base_name); let child_base = base.join(base_name);
let child_output = output.join(base_name); let child_right = right.join(base_name);
if child_right.is_dir() { let child_output = output.join(base_name);
sub_dirs.push(base_name.to_os_string()); if child_right.is_dir() {
} else if !child_base.exists() { sub_dirs.push(base_name.to_os_string());
// This overwrites the left side if that's been written. That's fine, since the } else if !child_base.exists() {
// point of the test is that it should be okay for either side to win. // This overwrites the left side if that's been written. That's fine, since the
std::fs::copy(&child_right, child_output).unwrap(); // point of the test is that it should be okay for either side to win.
std::fs::copy(&child_right, child_output).unwrap();
}
} }
} }
// Do the merge in subdirectories // Do the merge in subdirectories

View file

@ -93,13 +93,11 @@ impl TestRepo {
fs::create_dir(&repo_dir).unwrap(); fs::create_dir(&repo_dir).unwrap();
let repo = if use_git { let repo = if use_git {
let git_path = temp_dir.path().join("git-repo");
git2::Repository::init(&git_path).unwrap();
ReadonlyRepo::init( ReadonlyRepo::init(
&settings, &settings,
&repo_dir, &repo_dir,
|store_path| -> Result<Box<dyn Backend>, BackendInitError> { |store_path| -> Result<Box<dyn Backend>, BackendInitError> {
Ok(Box::new(GitBackend::init_external(store_path, &git_path)?)) Ok(Box::new(GitBackend::init_internal(store_path)?))
}, },
ReadonlyRepo::default_op_store_factory(), ReadonlyRepo::default_op_store_factory(),
ReadonlyRepo::default_op_heads_store_factory(), ReadonlyRepo::default_op_heads_store_factory(),
@ -144,9 +142,7 @@ impl TestWorkspace {
fs::create_dir(&workspace_root).unwrap(); fs::create_dir(&workspace_root).unwrap();
let (workspace, repo) = if use_git { let (workspace, repo) = if use_git {
let git_path = temp_dir.path().join("git-repo"); Workspace::init_internal_git(settings, &workspace_root).unwrap()
git2::Repository::init(&git_path).unwrap();
Workspace::init_external_git(settings, &workspace_root, &git_path).unwrap()
} else { } else {
Workspace::init_local(settings, &workspace_root).unwrap() Workspace::init_local(settings, &workspace_root).unwrap()
}; };