mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-26 22:10:52 +00:00
git: fix regression in pruning of remote refs
A while ago, I replaced a call to git2-rs's `Remote::fetch()` by calls to `Remote::download()` and `Remote::update_tips()`. The function is documented to be a convenience for those function, but it turns out that the pruning of deleted remote refs is a separate call (`Remote::prune()`), so we need to call that too.
This commit is contained in:
parent
bdea3ae31a
commit
27107637f2
2 changed files with 33 additions and 2 deletions
|
@ -14,7 +14,7 @@
|
|||
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
use git2::{FetchPrune, RemoteCallbacks};
|
||||
use git2::RemoteCallbacks;
|
||||
use itertools::Itertools;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -143,10 +143,10 @@ pub fn fetch(
|
|||
fetch_options.proxy_options(proxy_options);
|
||||
let callbacks = create_remote_callbacks();
|
||||
fetch_options.remote_callbacks(callbacks);
|
||||
fetch_options.prune(FetchPrune::On);
|
||||
let refspec: &[&str] = &[];
|
||||
remote.download(refspec, Some(&mut fetch_options))?;
|
||||
remote.update_tips(None, false, git2::AutotagOption::Unspecified, None)?;
|
||||
remote.prune(None)?;
|
||||
// TODO: We could make it optional to get the default branch since we only care
|
||||
// about it on clone.
|
||||
let mut default_branch = None;
|
||||
|
|
|
@ -327,6 +327,37 @@ fn test_fetch_success() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_prune_deleted_ref() {
|
||||
let settings = testutils::user_settings();
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let source_repo_dir = temp_dir.path().join("source");
|
||||
let clone_repo_dir = temp_dir.path().join("clone");
|
||||
let jj_repo_dir = temp_dir.path().join("jj");
|
||||
let source_git_repo = git2::Repository::init_bare(&source_repo_dir).unwrap();
|
||||
empty_git_commit(&source_git_repo, "refs/heads/main", &[]);
|
||||
let clone_git_repo =
|
||||
git2::Repository::clone(source_repo_dir.to_str().unwrap(), &clone_repo_dir).unwrap();
|
||||
std::fs::create_dir(&jj_repo_dir).unwrap();
|
||||
let jj_repo = ReadonlyRepo::init_external_git(&settings, jj_repo_dir, clone_repo_dir).unwrap();
|
||||
|
||||
let mut tx = jj_repo.start_transaction("test");
|
||||
git::fetch(tx.mut_repo(), &clone_git_repo, "origin").unwrap();
|
||||
// Test the setup
|
||||
assert!(tx.mut_repo().get_branch("main").is_some());
|
||||
|
||||
// After re-fetching, the branch should be deleted
|
||||
source_git_repo
|
||||
.find_reference("refs/heads/main")
|
||||
.unwrap()
|
||||
.delete()
|
||||
.unwrap();
|
||||
git::fetch(tx.mut_repo(), &clone_git_repo, "origin").unwrap();
|
||||
assert!(tx.mut_repo().get_branch("main").is_none());
|
||||
|
||||
tx.discard();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_no_default_branch() {
|
||||
let settings = testutils::user_settings();
|
||||
|
|
Loading…
Reference in a new issue