tests: make sure to specify external git repository path including ".git"

This commit is contained in:
Yuya Nishihara 2023-12-06 18:37:07 +09:00
parent c31b0f7614
commit 77c811163f
3 changed files with 23 additions and 18 deletions

View file

@ -1167,7 +1167,7 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let store_path = temp_dir.path();
let git_repo_path = temp_dir.path().join("git");
let git_repo = git2::Repository::init(&git_repo_path).unwrap();
let git_repo = git2::Repository::init(git_repo_path).unwrap();
// Add a commit with some files in
let blob1 = git_repo.blob(b"content1").unwrap();
@ -1223,7 +1223,7 @@ mod tests {
.unwrap();
let commit_id2 = CommitId::from_bytes(git_commit_id2.as_bytes());
let backend = GitBackend::init_external(&settings, store_path, &git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, git_repo.path()).unwrap();
// Import the head commit and its ancestors
backend
@ -1329,7 +1329,7 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let store_path = temp_dir.path();
let git_repo_path = temp_dir.path().join("git");
let git_repo = git2::Repository::init(&git_repo_path).unwrap();
let git_repo = git2::Repository::init(git_repo_path).unwrap();
let signature = git2::Signature::now("Someone", "someone@example.com").unwrap();
let empty_tree_id = Oid::from_str("4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap();
@ -1345,7 +1345,7 @@ mod tests {
)
.unwrap();
let backend = GitBackend::init_external(&settings, store_path, &git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, git_repo.path()).unwrap();
// read_commit() without import_head_commits() works as of now. This might be
// changed later.
@ -1369,7 +1369,7 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let store_path = temp_dir.path();
let git_repo_path = temp_dir.path().join("git");
let git_repo = git2::Repository::init(&git_repo_path).unwrap();
let git_repo = git2::Repository::init(git_repo_path).unwrap();
let signature = git2::Signature::now("Someone", "someone@example.com").unwrap();
let empty_tree_id = Oid::from_str("4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap();
@ -1394,7 +1394,7 @@ mod tests {
.commit_signed(commit_buf, secure_sig, None)
.unwrap();
let backend = GitBackend::init_external(&settings, store_path, &git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, git_repo.path()).unwrap();
let commit = backend
.read_commit(&CommitId::from_bytes(git_commit_id.as_bytes()))
@ -1461,9 +1461,9 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let store_path = temp_dir.path();
let git_repo_path = temp_dir.path().join("git");
let git_repo = git2::Repository::init(&git_repo_path).unwrap();
let git_repo = git2::Repository::init(git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, &git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, git_repo.path()).unwrap();
let mut commit = Commit {
parents: vec![],
predecessors: vec![],
@ -1526,9 +1526,9 @@ mod tests {
let temp_dir = testutils::new_temp_dir();
let store_path = temp_dir.path();
let git_repo_path = temp_dir.path().join("git");
let git_repo = git2::Repository::init(&git_repo_path).unwrap();
let git_repo = git2::Repository::init(git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, &git_repo_path).unwrap();
let backend = GitBackend::init_external(&settings, store_path, git_repo.path()).unwrap();
let create_tree = |i| {
let blob_id = git_repo.blob(b"content {i}").unwrap();
let mut tree_builder = git_repo.treebuilder(None).unwrap();

View file

@ -1113,7 +1113,7 @@ impl GitRepoData {
let origin_repo = git2::Repository::init_bare(&origin_repo_dir).unwrap();
let git_repo_dir = temp_dir.path().join("git");
let git_repo =
git2::Repository::clone(origin_repo_dir.to_str().unwrap(), &git_repo_dir).unwrap();
git2::Repository::clone(origin_repo_dir.to_str().unwrap(), git_repo_dir).unwrap();
let jj_repo_dir = temp_dir.path().join("jj");
std::fs::create_dir(&jj_repo_dir).unwrap();
let repo = ReadonlyRepo::init(
@ -1123,7 +1123,7 @@ impl GitRepoData {
Ok(Box::new(GitBackend::init_external(
settings,
store_path,
&git_repo_dir,
git_repo.path(),
)?))
},
Signer::from_settings(&settings).unwrap(),
@ -1979,7 +1979,7 @@ fn test_init() {
let temp_dir = testutils::new_temp_dir();
let git_repo_dir = temp_dir.path().join("git");
let jj_repo_dir = temp_dir.path().join("jj");
let git_repo = git2::Repository::init_bare(&git_repo_dir).unwrap();
let git_repo = git2::Repository::init_bare(git_repo_dir).unwrap();
let initial_git_commit = empty_git_commit(&git_repo, "refs/heads/main", &[]);
std::fs::create_dir(&jj_repo_dir).unwrap();
let repo = &ReadonlyRepo::init(
@ -1989,7 +1989,7 @@ fn test_init() {
Ok(Box::new(GitBackend::init_external(
settings,
store_path,
&git_repo_dir,
git_repo.path(),
)?))
},
Signer::from_settings(&settings).unwrap(),
@ -2306,7 +2306,8 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet
let jj_repo_dir = temp_dir.path().join("jj");
let source_repo = git2::Repository::init_bare(&source_repo_dir).unwrap();
let initial_git_commit = empty_git_commit(&source_repo, "refs/heads/main", &[]);
git2::Repository::clone(source_repo_dir.to_str().unwrap(), &clone_repo_dir).unwrap();
let clone_repo =
git2::Repository::clone(source_repo_dir.to_str().unwrap(), clone_repo_dir).unwrap();
std::fs::create_dir(&jj_repo_dir).unwrap();
let jj_repo = ReadonlyRepo::init(
settings,
@ -2315,7 +2316,7 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet
Ok(Box::new(GitBackend::init_external(
settings,
store_path,
&clone_repo_dir,
clone_repo.path(),
)?))
},
Signer::from_settings(settings).unwrap(),

View file

@ -108,8 +108,12 @@ fn test_init_external_git() {
let git_repo_path = uncanonical.join("git");
git2::Repository::init(&git_repo_path).unwrap();
std::fs::create_dir(uncanonical.join("jj")).unwrap();
let (workspace, repo) =
Workspace::init_external_git(&settings, &uncanonical.join("jj"), &git_repo_path).unwrap();
let (workspace, repo) = Workspace::init_external_git(
&settings,
&uncanonical.join("jj"),
&git_repo_path.join(".git"),
)
.unwrap();
let git_backend = repo
.store()
.backend_impl()