aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-common/src
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-07-14 20:58:20 +0100
committerGitHub <noreply@github.com>2023-07-14 19:58:20 +0000
commit465faca6d1255cb630de00e374a1675be25aa547 (patch)
treee8977ac6c11fadceb2a7140bafd42bafca353c37 /atuin-common/src
parentDelete the count cache row when a user is deleted (#1103) (diff)
downloadatuin-465faca6d1255cb630de00e374a1675be25aa547.zip
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
Diffstat (limited to 'atuin-common/src')
-rw-r--r--atuin-common/src/utils.rs25
1 files changed, 25 insertions, 0 deletions
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<PathBuf> {
+ 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.