From 465faca6d1255cb630de00e374a1675be25aa547 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Fri, 14 Jul 2023 20:58:20 +0100 Subject: Add workspace mode, enable if in git repo (#1053) * Add workspace mode, enable if in git repo * Fix tests * Should now be good * Page filter modes correctly if in workspace --- atuin-common/src/utils.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'atuin-common/src') diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs index 776a63de..d2db3acf 100644 --- a/atuin-common/src/utils.rs +++ b/atuin-common/src/utils.rs @@ -46,6 +46,31 @@ pub fn uuid_v4() -> String { Uuid::new_v4().as_simple().to_string() } +pub fn has_git_dir(path: &str) -> bool { + let mut gitdir = PathBuf::from(path); + gitdir.push(".git"); + + gitdir.exists() +} + +// detect if any parent dir has a git repo in it +// I really don't want to bring in libgit for something simple like this +// If we start to do anything more advanced, then perhaps +pub fn in_git_repo(path: &str) -> Option { + let mut gitdir = PathBuf::from(path); + + while gitdir.parent().is_some() && !has_git_dir(gitdir.to_str().unwrap()) { + gitdir.pop(); + } + + // No parent? then we hit root, finding no git + if gitdir.parent().is_some() { + return Some(gitdir); + } + + None +} + // TODO: more reliable, more tested // I don't want to use ProjectDirs, it puts config in awkward places on // mac. Data too. Seems to be more intended for GUI apps. -- cgit v1.3.1