mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 07:20:11 +00:00
git: try to fix flaky (?) fetch tests by keeping connection open longer
It seems it wasn't Windows that behaved differently when it comes getting the remote's default branch; the test failed on Ubuntu too. The documentation for `Remote::default_branch()` says that it can be called even after the connection has been closed, but let's see if calling it while the connection is open helps anyway. To do that, we have to replicate what `Remote::fetch()` does.
This commit is contained in:
parent
2086d1a84d
commit
eed715dc51
2 changed files with 9 additions and 5 deletions
|
@ -148,7 +148,14 @@ pub fn fetch(
|
|||
fetch_options.remote_callbacks(callbacks);
|
||||
fetch_options.prune(FetchPrune::On);
|
||||
let refspec: &[&str] = &[];
|
||||
remote.fetch(refspec, Some(&mut fetch_options), None)?;
|
||||
remote.download(refspec, Some(&mut fetch_options))?;
|
||||
// The FetchOptions above ate our RemoteCallbacks so it seems we need to create
|
||||
// a new instance.
|
||||
let mut callbacks = git2::RemoteCallbacks::new();
|
||||
callbacks.credentials(|_url, username_from_url, _allowed_types| {
|
||||
git2::Cred::ssh_key_from_agent(username_from_url.unwrap())
|
||||
});
|
||||
remote.update_tips(Some(&mut callbacks), false, git2::AutotagOption::All, 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;
|
||||
|
@ -161,6 +168,7 @@ pub fn fetch(
|
|||
}
|
||||
}
|
||||
}
|
||||
remote.disconnect()?;
|
||||
import_refs(mut_repo, git_repo).map_err(|err| match err {
|
||||
GitImportError::InternalGitError(source) => GitFetchError::InternalGitError(source),
|
||||
})?;
|
||||
|
|
|
@ -303,11 +303,7 @@ fn test_fetch_success() {
|
|||
let mut tx = jj_repo.start_transaction("test");
|
||||
let default_branch = git::fetch(tx.mut_repo(), &clone_git_repo, "origin").unwrap();
|
||||
// The default branch is "main"
|
||||
#[cfg(unix)]
|
||||
assert_eq!(default_branch, Some("main".to_string()));
|
||||
// TODO: Figure out why we don't find the remote's default branch on Windows.
|
||||
#[cfg(windows)]
|
||||
assert_eq!(default_branch, None);
|
||||
let repo = tx.commit();
|
||||
// The new commit is visible after git::fetch().
|
||||
assert!(repo.view().heads().contains(&commit_id(&new_git_commit)));
|
||||
|
|
Loading…
Reference in a new issue