mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-27 07:46:13 +00:00
feat(daemon): prune worktrees merged through a pull request
The daemon asks the forge (GitHub, Gitea/Forgejo) which pull requests were merged and removes the local worktree and branch of each merged head that holds no local work. Squash/rebase merges and head branches kept on the forge are covered; regenerable ignored output (target/, node_modules...) does not keep a worktree, any other ignored file does. The tip is kept in a refs/sync-backup/<machine>/<stamp>/merged/<branch> ref, and materialize no longer brings a pruned branch back unless it gets new commits. New config: sync.prune_merged (default true) and sync.prune_disposable. See docs/prune-merged.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011GZUAKXXztS4Hy4F4sSRkc
This commit is contained in:
19 files changed
+1070
-19
No files matched your search
@@ -159,6 +159,14 @@ pub struct Sync {
|
||||
/// syncing). Empty disables the move.
|
||||
#[serde(default = "default_purged_dir")]
|
||||
pub purged_dir: String,
|
||||
/// Remove worktrees whose branch was merged through a pull request on the forge (when they
|
||||
/// hold no local work).
|
||||
#[serde(default = "yes")]
|
||||
pub prune_merged: bool,
|
||||
/// Ignored files/directories (matched by name) that may be deleted with a pruned worktree:
|
||||
/// regenerable build output and dependency caches. Any other ignored file keeps it.
|
||||
#[serde(default = "default_disposable")]
|
||||
pub prune_disposable: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for Sync {
|
||||
@@ -170,6 +178,8 @@ impl Default for Sync {
|
||||
max_file_mb: default_max_file_mb(),
|
||||
snapshots: SnapshotPolicy::default(),
|
||||
purged_dir: default_purged_dir(),
|
||||
prune_merged: true,
|
||||
prune_disposable: default_disposable(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,6 +202,33 @@ fn default_max_file_mb() -> u64 {
|
||||
fn default_purged_dir() -> String {
|
||||
"Purged".into()
|
||||
}
|
||||
fn default_disposable() -> Vec<String> {
|
||||
[
|
||||
"target",
|
||||
"node_modules",
|
||||
".venv",
|
||||
"venv",
|
||||
"__pycache__",
|
||||
".pytest_cache",
|
||||
".mypy_cache",
|
||||
".ruff_cache",
|
||||
".tox",
|
||||
".gradle",
|
||||
".next",
|
||||
".nuxt",
|
||||
".svelte-kit",
|
||||
".turbo",
|
||||
".parcel-cache",
|
||||
"dist",
|
||||
"build",
|
||||
"out",
|
||||
"coverage",
|
||||
".cache",
|
||||
]
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
.collect()
|
||||
}
|
||||
fn default_fetch() -> u64 {
|
||||
60
|
||||
}
|
||||
@@ -296,6 +333,16 @@ impl Config {
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(d) = self
|
||||
.sync
|
||||
.prune_disposable
|
||||
.iter()
|
||||
.find(|d| d.is_empty() || *d == "." || *d == ".." || d.contains(['/', '\\']))
|
||||
{
|
||||
return bad(format!(
|
||||
"sync.prune_disposable entry {d:?} must be a plain file or directory name"
|
||||
));
|
||||
}
|
||||
for g in &self.groups {
|
||||
// Group names are directory names under the root.
|
||||
if g.name.is_empty() || g.name.starts_with('.') || g.name.contains(['/', '\\']) {
|
||||
@@ -404,6 +451,22 @@ name = "grove-config"
|
||||
assert_eq!(c.root_path(), PathBuf::from("/x"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prune_merged_defaults_on_and_disposable_names_are_plain() {
|
||||
let base = "[machine]\nname=\"m\"\n[root]\npath=\"/x\"\n";
|
||||
let c = Config::parse(base).unwrap();
|
||||
assert!(c.sync.prune_merged);
|
||||
assert!(c.sync.prune_disposable.iter().any(|d| d == "target"));
|
||||
let own = format!("{base}[sync]\nprune_merged=false\nprune_disposable=[\"out\"]\n");
|
||||
let c = Config::parse(&own).unwrap();
|
||||
assert!(!c.sync.prune_merged);
|
||||
assert_eq!(c.sync.prune_disposable, vec!["out".to_string()]);
|
||||
for bad in ["\"\"", "\"a/b\"", "\"..\""] {
|
||||
let t = format!("{base}[sync]\nprune_disposable=[{bad}]\n");
|
||||
assert!(Config::parse(&t).is_err(), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn purged_dir_defaults_and_must_not_be_a_group() {
|
||||
let base = "[machine]\nname=\"a\"\n[root]\npath=\"/x\"\n[providers.p]\nkind=\"github\"\n";
|
||||
|
||||
Reference in new issue
Block a user