use std::path::PathBuf;
use git_global::{Config, Repo};
#[allow(dead_code)]
pub fn with_temp_repo<T>(test: T) -> ()
where
T: FnOnce(Repo) -> (),
{
let tempdir = tempfile::tempdir().unwrap();
let repo_path = tempdir.path();
git2::Repository::init(repo_path).unwrap();
let repo = Repo::new(repo_path.to_str().unwrap().to_string());
test(repo);
}
#[allow(dead_code)]
pub fn with_base_dir_of_three_repos<T>(test: T) -> ()
where
T: FnOnce(Config) -> (),
{
let tempdir = tempfile::tempdir().unwrap();
let base_path = tempdir.path();
for repo_name in ["a", "b", "c"].iter() {
let mut repo_path = PathBuf::from(base_path);
repo_path.push(repo_name);
git2::Repository::init(repo_path).unwrap();
}
let config = Config {
basedir: base_path.to_path_buf(),
follow_symlinks: true,
same_filesystem: true,
ignored_patterns: vec![],
default_cmd: String::from("status"),
verbose: false,
show_untracked: true,
cache_file: Some(base_path.join("test-cache-file.txt").to_path_buf()),
manpage_file: None,
};
test(config);
}