+
+ #[test]
+ fn prune() {
+ let (td, remote_repo) = crate::test::repo_init();
+ let oid = remote_repo.head().unwrap().target().unwrap();
+ let commit = remote_repo.find_commit(oid).unwrap();
+ remote_repo.branch("stale", &commit, true).unwrap();
+
+ let td2 = TempDir::new().unwrap();
+ let url = crate::test::path2url(&td.path());
+ let repo = Repository::clone(&url, &td2).unwrap();
+
+ fn assert_branch_count(repo: &Repository, count: usize) {
+ assert_eq!(
+ repo.branches(Some(crate::BranchType::Remote))
+ .unwrap()
+ .filter(|b| b.as_ref().unwrap().0.name().unwrap() == Some("origin/stale"))
+ .count(),
+ count,
+ );
+ }
+
+ assert_branch_count(&repo, 1);
+
+ // delete `stale` branch on remote repo
+ let mut stale_branch = remote_repo
+ .find_branch("stale", crate::BranchType::Local)
+ .unwrap();
+ stale_branch.delete().unwrap();
+
+ // prune
+ let mut remote = repo.find_remote("origin").unwrap();
+ remote.connect(Direction::Push).unwrap();
+ let mut callbacks = RemoteCallbacks::new();
+ callbacks.update_tips(|refname, _a, b| {
+ assert_eq!(refname, "refs/remotes/origin/stale");
+ assert!(b.is_zero());
+ true
+ });
+ remote.prune(Some(callbacks)).unwrap();
+ assert_branch_count(&repo, 0);
+ }