From 02b49de61c689f148fc8e7a1f821cc5210e0363f Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 1 Jan 2021 22:07:34 +0800 Subject: [PATCH 1/3] fix: set search path before init repos --- crates/cargo-test-support/src/git.rs | 15 +++++++++++++++ crates/cargo-test-support/src/paths.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/cargo-test-support/src/git.rs b/crates/cargo-test-support/src/git.rs index c698fded541..cc6b0c7462a 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 61f9c03aea4..2a976987d79 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' From 332887e4aa361ec09095a240b1adfe96a7e22d87 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 1 Jan 2021 23:36:23 +0800 Subject: [PATCH 2/3] test: remove odd semicolon --- tests/testsuite/cache_messages.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/cache_messages.rs b/tests/testsuite/cache_messages.rs index d823a4d2528..b02c133a5ae 100644 --- a/tests/testsuite/cache_messages.rs +++ b/tests/testsuite/cache_messages.rs @@ -105,7 +105,7 @@ fn color() { return s.replace("\x1b[0m\x1b[0m", "\x1b[0m"); #[cfg(not(windows))] return s.to_string(); - }; + } let compare = |a, b| { assert_eq!(normalize(a), normalize(b)); From 06d65a48f82e19ae457ef99c6a0743cfbdfd6d75 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 22 Jan 2021 23:27:44 +0800 Subject: [PATCH 3/3] chore: bump versions of git2 and libgit2-sys --- Cargo.toml | 4 ++-- crates/cargo-test-support/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25cb8c1cacc..7c4e3ab6257 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index 0340c466765..0c62e2da1fa 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -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"