mirror of
https://github.com/rust-lang/cargo
synced 2024-09-19 07:41:57 +00:00
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:
commit
638f33d036
|
@ -32,7 +32,7 @@ pretty_env_logger = { version = "0.4", optional = true }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
filetime = "0.2.9"
|
filetime = "0.2.9"
|
||||||
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
|
flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] }
|
||||||
git2 = "0.13.14"
|
git2 = "0.13.16"
|
||||||
git2-curl = "0.14.1"
|
git2-curl = "0.14.1"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
@ -44,7 +44,7 @@ jobserver = "0.1.21"
|
||||||
lazycell = "1.2.0"
|
lazycell = "1.2.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
libgit2-sys = "0.12.16"
|
libgit2-sys = "0.12.18"
|
||||||
memchr = "2.1.3"
|
memchr = "2.1.3"
|
||||||
num_cpus = "1.0"
|
num_cpus = "1.0"
|
||||||
opener = "0.4"
|
opener = "0.4"
|
||||||
|
|
|
@ -13,7 +13,7 @@ cargo = { path = "../.." }
|
||||||
cargo-test-macro = { path = "../cargo-test-macro" }
|
cargo-test-macro = { path = "../cargo-test-macro" }
|
||||||
filetime = "0.2"
|
filetime = "0.2"
|
||||||
flate2 = { version = "1.0", default-features = false, features = ["zlib"] }
|
flate2 = { version = "1.0", default-features = false, features = ["zlib"] }
|
||||||
git2 = "0.13"
|
git2 = "0.13.16"
|
||||||
glob = "0.3"
|
glob = "0.3"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
remove_dir_all = "0.5"
|
remove_dir_all = "0.5"
|
||||||
|
|
|
@ -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 crate::{path2url, project, Project, ProjectBuilder};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Once;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -124,11 +125,25 @@ impl Repository {
|
||||||
|
|
||||||
/// Initialize a new repository at the given path.
|
/// Initialize a new repository at the given path.
|
||||||
pub fn init(path: &Path) -> git2::Repository {
|
pub fn init(path: &Path) -> git2::Repository {
|
||||||
|
default_search_path();
|
||||||
let repo = t!(git2::Repository::init(path));
|
let repo = t!(git2::Repository::init(path));
|
||||||
default_repo_cfg(&repo);
|
default_repo_cfg(&repo);
|
||||||
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) {
|
fn default_repo_cfg(repo: &git2::Repository) {
|
||||||
let mut cfg = t!(repo.config());
|
let mut cfg = t!(repo.config());
|
||||||
t!(cfg.set_str("user.email", "foo@bar.com"));
|
t!(cfg.set_str("user.email", "foo@bar.com"));
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::sync::Mutex;
|
||||||
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
|
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref GLOBAL_ROOT: PathBuf = {
|
pub static ref GLOBAL_ROOT: PathBuf = {
|
||||||
let mut path = t!(env::current_exe());
|
let mut path = t!(env::current_exe());
|
||||||
path.pop(); // chop off exe name
|
path.pop(); // chop off exe name
|
||||||
path.pop(); // chop off 'debug'
|
path.pop(); // chop off 'debug'
|
||||||
|
|
Loading…
Reference in a new issue