feat: add get_git_base_dir
This commit is contained in:
19
src/git.rs
19
src/git.rs
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user