fix: set search path before init repos

This commit is contained in:
Weihang Lo 2021-01-01 22:07:34 +08:00
parent cf8800a150
commit 02b49de61c
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 16 additions and 1 deletions

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'