mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
fix: set search path before init repos
This commit is contained in:
parent
cf8800a150
commit
02b49de61c
@ -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"));
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user