2023-08-28 10:44:04 +03:00
|
|
|
use std::{fs, path};
|
2023-08-28 10:34:30 +03:00
|
|
|
|
|
|
|
use tempfile::tempdir;
|
|
|
|
|
|
|
|
pub fn temp_dir() -> path::PathBuf {
|
|
|
|
let path = tempdir().unwrap().path().to_path_buf();
|
|
|
|
fs::create_dir_all(&path).unwrap();
|
|
|
|
path
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn test_repository() -> git2::Repository {
|
|
|
|
let path = temp_dir();
|
|
|
|
let repository = git2::Repository::init(path).expect("failed to init repository");
|
|
|
|
let mut index = repository.index().expect("failed to get index");
|
|
|
|
let oid = index.write_tree().expect("failed to write tree");
|
|
|
|
let signature = git2::Signature::now("test", "test@email.com").unwrap();
|
|
|
|
repository
|
|
|
|
.commit(
|
|
|
|
Some("HEAD"),
|
|
|
|
&signature,
|
|
|
|
&signature,
|
|
|
|
"Initial commit",
|
|
|
|
&repository.find_tree(oid).expect("failed to find tree"),
|
|
|
|
&[],
|
|
|
|
)
|
|
|
|
.expect("failed to commit");
|
|
|
|
repository
|
|
|
|
}
|