Skip to content

Commit 638f33d

Browse files
committed
Auto merge of #9035 - weihanglo:fix/git-init-search-path, r=alexcrichton
Fix: set default git config search path for tests Fixes #8863 by setting the default config search path. Just wait rust-lang/git2-rs#656 being merged and update Cargo.toml the new release of git2-rs 😄
2 parents ba3311e + 06d65a4 commit 638f33d

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pretty_env_logger = { version = "0.4", optional = true }
3232
anyhow = "1.0"
3333
filetime = "0.2.9"
3434
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
35-
git2 = "0.13.14"
35+
git2 = "0.13.16"
3636
git2-curl = "0.14.1"
3737
glob = "0.3.0"
3838
hex = "0.4"
@@ -44,7 +44,7 @@ jobserver = "0.1.21"
4444
lazycell = "1.2.0"
4545
libc = "0.2"
4646
log = "0.4.6"
47-
libgit2-sys = "0.12.16"
47+
libgit2-sys = "0.12.18"
4848
memchr = "2.1.3"
4949
num_cpus = "1.0"
5050
opener = "0.4"

crates/cargo-test-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cargo = { path = "../.." }
1313
cargo-test-macro = { path = "../cargo-test-macro" }
1414
filetime = "0.2"
1515
flate2 = { version = "1.0", default-features = false, features = ["zlib"] }
16-
git2 = "0.13"
16+
git2 = "0.13.16"
1717
glob = "0.3"
1818
lazy_static = "1.0"
1919
remove_dir_all = "0.5"

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", "[email protected]"));

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)