diff --git a/crates/cargo-test-support/src/git.rs b/crates/cargo-test-support/src/git.rs index c698fded5..cc6b0c746 100644 --- a/crates/cargo-test-support/src/git.rs +++ b/crates/cargo-test-support/src/git.rs @@ -41,6 +41,7 @@ use some of the helper functions in this file to interact with the repository. use crate::{path2url, project, Project, ProjectBuilder}; use std::fs; use std::path::{Path, PathBuf}; +use std::sync::Once; use url::Url; #[must_use] @@ -124,11 +125,25 @@ impl Repository { /// Initialize a new repository at the given path. pub fn init(path: &Path) -> git2::Repository { + default_search_path(); let repo = t!(git2::Repository::init(path)); default_repo_cfg(&repo); repo } +fn default_search_path() { + use crate::paths::GLOBAL_ROOT; + use git2::{opts::set_search_path, ConfigLevel}; + static INIT: Once = Once::new(); + INIT.call_once(|| unsafe { + let path = GLOBAL_ROOT.join("blank_git_search_path"); + t!(set_search_path(ConfigLevel::System, &path)); + t!(set_search_path(ConfigLevel::Global, &path)); + t!(set_search_path(ConfigLevel::XDG, &path)); + t!(set_search_path(ConfigLevel::ProgramData, &path)); + }) +} + fn default_repo_cfg(repo: &git2::Repository) { let mut cfg = t!(repo.config()); t!(cfg.set_str("user.email", "foo@bar.com")); diff --git a/crates/cargo-test-support/src/paths.rs b/crates/cargo-test-support/src/paths.rs index 61f9c03ae..2a976987d 100644 --- a/crates/cargo-test-support/src/paths.rs +++ b/crates/cargo-test-support/src/paths.rs @@ -14,7 +14,7 @@ use std::sync::Mutex; static CARGO_INTEGRATION_TEST_DIR: &str = "cit"; lazy_static! { - static ref GLOBAL_ROOT: PathBuf = { + pub static ref GLOBAL_ROOT: PathBuf = { let mut path = t!(env::current_exe()); path.pop(); // chop off exe name path.pop(); // chop off 'debug'