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
@@ -481,3 +481,48 @@ fn git_url_follows_the_protocol_and_needs_an_ssh_url_for_ssh() {
|
||||
);
|
||||
assert!(r[1].git_url(Protocol::Ssh).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merged_pulls_keep_only_merged_same_repo_heads() {
|
||||
// Merged, closed without merging, merged from a fork, merged from a deleted fork.
|
||||
let gitea = r#"[
|
||||
{"number":3,"merged":true,"head":{"ref":"feat/a","sha":"aaa","repo":{"full_name":"O/r"}},"base":{"repo":{"full_name":"o/r"}}},
|
||||
{"number":2,"merged":false,"head":{"ref":"b","sha":"bbb","repo":{"full_name":"o/r"}},"base":{"repo":{"full_name":"o/r"}}},
|
||||
{"number":1,"merged":true,"head":{"ref":"c","sha":"ccc","repo":{"full_name":"x/r"}},"base":{"repo":{"full_name":"o/r"}}},
|
||||
{"number":0,"merged":true,"head":{"ref":"d","sha":"ddd","repo":null},"base":{"repo":{"full_name":"o/r"}}}
|
||||
]"#;
|
||||
let (url, rx) = mock(vec![(200, gitea)]);
|
||||
let pulls = Gitea::new(ProviderKind::Forgejo, &url, "t".into())
|
||||
.merged_pulls("o", "r")
|
||||
.unwrap();
|
||||
assert!(
|
||||
rx.recv()
|
||||
.unwrap()
|
||||
.starts_with("GET /api/v1/repos/o/r/pulls?state=closed&sort=recentupdate&limit=50 ")
|
||||
);
|
||||
assert_eq!(pulls.len(), 1);
|
||||
assert_eq!(
|
||||
(
|
||||
pulls[0].number,
|
||||
pulls[0].head_ref.as_str(),
|
||||
pulls[0].head_sha.as_str()
|
||||
),
|
||||
(3, "feat/a", "aaa")
|
||||
);
|
||||
|
||||
let github = r#"[
|
||||
{"number":9,"merged_at":"2026-01-01T00:00:00Z","head":{"ref":"x","sha":"999","repo":{"full_name":"o/r"}},"base":{"repo":{"full_name":"o/r"}}},
|
||||
{"number":8,"merged_at":null,"head":{"ref":"y","sha":"888","repo":{"full_name":"o/r"}},"base":{"repo":{"full_name":"o/r"}}}
|
||||
]"#;
|
||||
let (url, rx) = mock(vec![(200, github), (404, r#"{"message":"Not Found"}"#)]);
|
||||
let gh = GitHub::new(&url, "t".into());
|
||||
let pulls = gh.merged_pulls("o", "r").unwrap();
|
||||
assert!(rx.recv().unwrap().starts_with(
|
||||
"GET /repos/o/r/pulls?state=closed&sort=updated&direction=desc&per_page=100 "
|
||||
));
|
||||
assert_eq!(pulls.iter().map(|p| p.number).collect::<Vec<_>>(), vec![9]);
|
||||
assert!(matches!(
|
||||
gh.merged_pulls("o", "gone").unwrap_err(),
|
||||
Error::Api { status: 404, .. }
|
||||
));
|
||||
}
|
||||
Reference in new issue
Block a user