Skip to content

Commit

Permalink
Auto merge of #9035 - weihanglo:fix/git-init-search-path, r=alexcrichton
Browse files Browse the repository at this point in the history
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 😄
  • Loading branch information
bors committed Jan 22, 2021
2 parents ba3311e + 06d65a4 commit 638f33d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-test-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions crates/cargo-test-support/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 638f33d

Please sign in to comment.