From 3dc0e82ad6213040636ab71ae218827f12243665 Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 28 Feb 2024 14:26:25 -0500 Subject: [PATCH] added helper function for finding repository root --- src/util.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util.rs b/src/util.rs index ce3c63a..bf1e17b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,6 @@ use std::{ env::var, + path::PathBuf, process::exit }; @@ -36,3 +37,14 @@ pub fn session_exists(target: String) -> bool { .success() } +/// recursively attempt to find a git root directory +fn repo_root(path: PathBuf) -> Option { + // 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 } +} +