mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
feat(daemon): add groved with inotify watching, scheduler and IPC
Debounced per-repo passes, periodic full pass, exponential backoff, pause and resume, JSON protocol over a Unix socket, activity log, grove daemon CLI client and a systemd user unit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a631d0a90f
commit
41ef589e58
13 files changed
+1480
-1
No files matched your search
@@ -0,0 +1,59 @@
|
||||
//! Finds the repos managed under the workspace root: `root/<repo>` or `root/<group>/<repo>`,
|
||||
//! where a repo has a `.bare` directory (bare + worktrees layout) or a `.git`.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn is_repo(p: &Path) -> bool {
|
||||
p.join(".bare").is_dir() || p.join(".git").exists()
|
||||
}
|
||||
|
||||
fn subdirs(p: &Path) -> Vec<PathBuf> {
|
||||
let mut v: Vec<PathBuf> = std::fs::read_dir(p)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter(|e| e.file_type().is_ok_and(|t| t.is_dir()))
|
||||
.filter(|e| !e.file_name().to_string_lossy().starts_with('.'))
|
||||
.map(|e| e.path())
|
||||
.collect();
|
||||
v.sort();
|
||||
v
|
||||
}
|
||||
|
||||
pub fn discover(root: &Path) -> Vec<PathBuf> {
|
||||
let mut out = Vec::new();
|
||||
for child in subdirs(root) {
|
||||
if is_repo(&child) {
|
||||
out.push(child);
|
||||
} else {
|
||||
out.extend(subdirs(&child).into_iter().filter(|g| is_repo(g)));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn finds_repos_at_depth_one_and_two_and_skips_hidden() {
|
||||
let base = std::env::temp_dir().join(format!("grove-disc-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
for d in [
|
||||
"a/.git",
|
||||
"grp/b/.bare",
|
||||
"grp/plain",
|
||||
".hidden/.git",
|
||||
"c/inner/.git",
|
||||
] {
|
||||
std::fs::create_dir_all(base.join(d)).unwrap();
|
||||
}
|
||||
let found = discover(&base);
|
||||
assert_eq!(
|
||||
found,
|
||||
vec![base.join("a"), base.join("c/inner"), base.join("grp/b")]
|
||||
);
|
||||
std::fs::remove_dir_all(&base).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user