diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-07-14 20:58:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 19:58:20 +0000 |
| commit | 465faca6d1255cb630de00e374a1675be25aa547 (patch) | |
| tree | e8977ac6c11fadceb2a7140bafd42bafca353c37 /atuin-common/src | |
| parent | Delete the count cache row when a user is deleted (#1103) (diff) | |
| download | atuin-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.rs | 25 |
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. |
