Skip to content

Commit

Permalink
git: Introduce depth argument for fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Sep 19, 2024
1 parent 0626501 commit d222829
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/src/commands/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ fn do_git_clone(
git::fetch(
fetch_tx.repo_mut(),
&git_repo,
None,
remote_name,
&[StringPattern::everything()],
cb,
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/git/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn cmd_git_fetch(
git::fetch(
tx.repo_mut(),
&git_repo,
None,
remote,
&args.branch,
cb,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::collections::HashSet;
use std::default::Default;
use std::fmt;
use std::io::Read;
use std::num::NonZeroU32;
use std::path::PathBuf;
use std::str;

Expand Down Expand Up @@ -1240,6 +1241,7 @@ pub struct GitFetchStats {
pub fn fetch(
mut_repo: &mut MutableRepo,
git_repo: &git2::Repository,
depth: Option<NonZeroU32>,
remote_name: &str,
branch_names: &[StringPattern],
callbacks: RemoteCallbacks<'_>,
Expand All @@ -1260,6 +1262,9 @@ pub fn fetch(
fetch_options.proxy_options(proxy_options);
let callbacks = callbacks.into_git();
fetch_options.remote_callbacks(callbacks);
if let Some(depth) = depth.and_then(|depth| depth.get().try_into().ok()) {
fetch_options.depth(depth);
}
// At this point, we are only updating Git's remote tracking branches, not the
// local branches.
let refspecs: Vec<_> = branch_names
Expand Down
10 changes: 10 additions & 0 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,7 @@ fn test_fetch_empty_repo() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2292,6 +2293,7 @@ fn test_fetch_initial_commit() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2342,6 +2344,7 @@ fn test_fetch_success() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2365,6 +2368,7 @@ fn test_fetch_success() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2422,6 +2426,7 @@ fn test_fetch_prune_deleted_ref() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2445,6 +2450,7 @@ fn test_fetch_prune_deleted_ref() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2472,6 +2478,7 @@ fn test_fetch_no_default_branch() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2495,6 +2502,7 @@ fn test_fetch_no_default_branch() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2516,6 +2524,7 @@ fn test_fetch_empty_refspecs() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"origin",
&[],
git::RemoteCallbacks::default(),
Expand All @@ -2542,6 +2551,7 @@ fn test_fetch_no_such_remote() {
let result = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
None,
"invalid-remote",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down

0 comments on commit d222829

Please sign in to comment.