Skip to content

Commit 02b49de

Browse files
committed
fix: set search path before init repos
1 parent cf8800a commit 02b49de

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/cargo-test-support/src/git.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use some of the helper functions in this file to interact with the repository.
4141
use crate::{path2url, project, Project, ProjectBuilder};
4242
use std::fs;
4343
use std::path::{Path, PathBuf};
44+
use std::sync::Once;
4445
use url::Url;
4546

4647
#[must_use]
@@ -124,11 +125,25 @@ impl Repository {
124125

125126
/// Initialize a new repository at the given path.
126127
pub fn init(path: &Path) -> git2::Repository {
128+
default_search_path();
127129
let repo = t!(git2::Repository::init(path));
128130
default_repo_cfg(&repo);
129131
repo
130132
}
131133

134+
fn default_search_path() {
135+
use crate::paths::GLOBAL_ROOT;
136+
use git2::{opts::set_search_path, ConfigLevel};
137+
static INIT: Once = Once::new();
138+
INIT.call_once(|| unsafe {
139+
let path = GLOBAL_ROOT.join("blank_git_search_path");
140+
t!(set_search_path(ConfigLevel::System, &path));
141+
t!(set_search_path(ConfigLevel::Global, &path));
142+
t!(set_search_path(ConfigLevel::XDG, &path));
143+
t!(set_search_path(ConfigLevel::ProgramData, &path));
144+
})
145+
}
146+
132147
fn default_repo_cfg(repo: &git2::Repository) {
133148
let mut cfg = t!(repo.config());
134149
t!(cfg.set_str("user.email", "foo@bar.com"));

crates/cargo-test-support/src/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::sync::Mutex;
1414
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
1515

1616
lazy_static! {
17-
static ref GLOBAL_ROOT: PathBuf = {
17+
pub static ref GLOBAL_ROOT: PathBuf = {
1818
let mut path = t!(env::current_exe());
1919
path.pop(); // chop off exe name
2020
path.pop(); // chop off 'debug'

0 commit comments

Comments
 (0)