git: when fetching, prune refs that have been deleted on the remote

Otherwise remote-tracking branches just pile up.

It seems that both git and libgit2 remove the remote-tracking branch
when you push a deletion, so `jj branch --delete foo; jj git push
--branch foo` already sees `foo` disappear locally as well. However,
if a branch has been deleted on the remote, we would never know before
this change.
This commit is contained in:
Martin von Zweigbergk 2021-08-04 16:54:44 -07:00
parent 8b8aff171e
commit d555e0c326

View file

@ -14,6 +14,7 @@
use std::collections::BTreeMap;
use git2::FetchPrune;
use thiserror::Error;
use crate::commit::Commit;
@ -144,6 +145,7 @@ pub fn fetch(
});
let mut fetch_options = git2::FetchOptions::new();
fetch_options.remote_callbacks(callbacks);
fetch_options.prune(FetchPrune::On);
let refspec: &[&str] = &[];
remote.fetch(refspec, Some(&mut fetch_options), None)?;
import_refs(mut_repo, git_repo).map_err(|err| match err {