Auto merge of #9035 - weihanglo:fix/git-init-search-path, r=alexcrichton

Fix: set default git config search path for tests

Fixes https://github.com/rust-lang/cargo/issues/8863 by setting the default config search path.

Just wait https://github.com/rust-lang/git2-rs/pull/656 being merged and update Cargo.toml the new release of git2-rs 😄
This commit is contained in:
bors 2021-01-22 15:29:39 +00:00
commit 638f33d036
4 changed files with 19 additions and 4 deletions

View file

@ -32,7 +32,7 @@ pretty_env_logger = { version = "0.4", optional = true }
anyhow = "1.0"
filetime = "0.2.9"
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
git2 = "0.13.14"
git2 = "0.13.16"
git2-curl = "0.14.1"
glob = "0.3.0"
hex = "0.4"
@ -44,7 +44,7 @@ jobserver = "0.1.21"
lazycell = "1.2.0"
libc = "0.2"
log = "0.4.6"
libgit2-sys = "0.12.16"
libgit2-sys = "0.12.18"
memchr = "2.1.3"
num_cpus = "1.0"
opener = "0.4"

View file

@ -13,7 +13,7 @@ cargo = { path = "../.." }
cargo-test-macro = { path = "../cargo-test-macro" }
filetime = "0.2"
flate2 = { version = "1.0", default-features = false, features = ["zlib"] }
git2 = "0.13"
git2 = "0.13.16"
glob = "0.3"
lazy_static = "1.0"
remove_dir_all = "0.5"

View file

@ -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"));

View file

@ -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'