feat: add get_git_base_dir

This commit is contained in:
2020-07-26 11:07:30 +08:00
parent b3bf0b99b9
commit db51056cd1

View File

@@ -1,5 +1,24 @@
use std::path::PathBuf;
use std::process::Command;
pub fn get_git_base_path() -> Option<PathBuf> {
match PathBuf::from(".").canonicalize() {
Err(e) => {
warn!("Get current path failed: {}", e);
None
},
Ok(mut path) => loop {
if path.join(".git").is_dir() {
debug!("Found git base dir: {:?}", path)
return Some(path);
}
if !path.pop() {
return None;
}
}
}
}
pub fn check_git_status() -> bool {
trace!("Run: git fetch --dry-run");
match Command::new("git").env("LANG", "en_US").args(&["fetch", "--dry-run"]).output() {