diff --git a/src/remote.rs b/src/remote.rs index f36db6844b..c8f5a935a6 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> { /// Options which can be specified to various fetch operations. pub struct FetchOptions<'cb> { callbacks: Option>, + depth: i32, proxy: Option>, prune: FetchPrune, update_fetchhead: bool, @@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> { follow_redirects: RemoteRedirect::Initial, custom_headers: Vec::new(), custom_headers_ptrs: Vec::new(), + depth: 0, // Not limited depth } } @@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> { self } + /// Set fetch depth, a value less or equal to 0 is interpreted as pull + /// everything (effectively the same as not declaring a limit depth). + + // FIXME(blyxyas): We currently don't have a test for shallow functions + // because libgit2 doesn't support local shallow clones. + // https://github.com/rust-lang/git2-rs/pull/979#issuecomment-1716299900 + pub fn depth(&mut self, depth: i32) -> &mut Self { + self.depth = depth.max(0); + self + } + /// Set how to behave regarding tags on the remote, such as auto-downloading /// tags for objects we're downloading or downloading all of them. /// @@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> { prune: crate::call::convert(&self.prune), update_fetchhead: crate::call::convert(&self.update_fetchhead), download_tags: crate::call::convert(&self.download_tags), - depth: 0, // GIT_FETCH_DEPTH_FULL. + depth: self.depth, follow_redirects: self.follow_redirects.raw(), custom_headers: git_strarray { count: self.custom_headers_ptrs.len(),