diff --git a/lib/src/git.rs b/lib/src/git.rs index ecccadc75..050e1e63c 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -342,7 +342,7 @@ pub fn fetch( mut_repo: &mut MutableRepo, git_repo: &git2::Repository, remote_name: &str, - globs: &[&str], + branch_name_globs: Option<&[&str]>, callbacks: RemoteCallbacks<'_>, git_settings: &GitSettings, ) -> Result, GitFetchError> { @@ -364,15 +364,19 @@ pub fn fetch( fetch_options.proxy_options(proxy_options); let callbacks = callbacks.into_git(); fetch_options.remote_callbacks(callbacks); - if globs.iter().any(|g| g.contains(|c| ":^".contains(c))) { - return Err(GitFetchError::InvalidGlob); - } - // At this point, we are only updating Git's remote tracking branches, not the - // local branches. - let refspecs = globs - .iter() - .map(|glob| format!("+refs/heads/{glob}:refs/remotes/{remote_name}/{glob}")) - .collect_vec(); + let refspecs = if let Some(globs) = branch_name_globs { + if globs.iter().any(|g| g.contains(|c| ":^".contains(c))) { + return Err(GitFetchError::InvalidGlob); + } + // At this point, we are only updating Git's remote tracking branches, not the + // local branches. + globs + .iter() + .map(|glob| format!("+refs/heads/{glob}:refs/remotes/{remote_name}/{glob}")) + .collect_vec() + } else { + vec![] + }; tracing::debug!("remote.download"); remote.download(&refspecs, Some(&mut fetch_options))?; tracing::debug!("remote.prune"); diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 8d2e2c9ff..e689499a5 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -957,7 +957,7 @@ fn test_fetch_empty_repo() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -981,7 +981,7 @@ fn test_fetch_initial_commit() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1023,7 +1023,7 @@ fn test_fetch_success() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1044,7 +1044,7 @@ fn test_fetch_success() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1086,7 +1086,7 @@ fn test_fetch_prune_deleted_ref() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1105,7 +1105,7 @@ fn test_fetch_prune_deleted_ref() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1126,7 +1126,7 @@ fn test_fetch_no_default_branch() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1149,7 +1149,7 @@ fn test_fetch_no_default_branch() { tx.mut_repo(), &test_data.git_repo, "origin", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ) @@ -1169,7 +1169,7 @@ fn test_fetch_no_such_remote() { tx.mut_repo(), &test_data.git_repo, "invalid-remote", - &[], + None, git::RemoteCallbacks::default(), &git_settings, ); diff --git a/src/commands/git.rs b/src/commands/git.rs index 724638b5d..7ba72b1a3 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -302,7 +302,7 @@ fn cmd_git_fetch( tx.mut_repo(), &git_repo, &remote, - &branches, + (!branches.is_empty()).then(|| &*branches), cb, &command.settings().git_settings(), ) @@ -430,7 +430,7 @@ fn do_git_clone( fetch_tx.mut_repo(), &git_repo, remote_name, - &[], + None, cb, &command.settings().git_settings(), )