added helper function for finding repository root

This commit is contained in:
Valerie Wolfe 2024-02-28 14:26:25 -05:00
parent 7aa6b225de
commit 3dc0e82ad6

View file

@ -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 }
}