added helper function for finding repository root
This commit is contained in:
parent
7aa6b225de
commit
3dc0e82ad6
1 changed files with 12 additions and 0 deletions
12
src/util.rs
12
src/util.rs
|
@ -1,5 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::var,
|
env::var,
|
||||||
|
path::PathBuf,
|
||||||
process::exit
|
process::exit
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,3 +37,14 @@ pub fn session_exists(target: String) -> bool {
|
||||||
.success()
|
.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// recursively attempt to find a git root directory
|
||||||
|
fn repo_root(path: PathBuf) -> Option<PathBuf> {
|
||||||
|
// if .git dir is found, return
|
||||||
|
if path.join(".git").exists() { return Some(path); }
|
||||||
|
|
||||||
|
// otherwise, attempt to traverse
|
||||||
|
let parent = path.parent();
|
||||||
|
if let Some(parent) = parent { git_traverse(parent.to_path_buf()) }
|
||||||
|
else { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue