@@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> {
4141/// Options which can be specified to various fetch operations.
4242pub struct FetchOptions < ' cb > {
4343 callbacks : Option < RemoteCallbacks < ' cb > > ,
44+ depth : i32 ,
4445 proxy : Option < ProxyOptions < ' cb > > ,
4546 prune : FetchPrune ,
4647 update_fetchhead : bool ,
@@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> {
509510 follow_redirects : RemoteRedirect :: Initial ,
510511 custom_headers : Vec :: new ( ) ,
511512 custom_headers_ptrs : Vec :: new ( ) ,
513+ depth : 0 , // Not limited depth
512514 }
513515 }
514516
@@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> {
538540 self
539541 }
540542
543+ /// Set fetch depth, a value less or equal to 0 is interpreted as pull
544+ /// everything (effectively the same as not declaring a limit depth).
545+
546+ // FIXME(blyxyas): We currently don't have a test for shallow functions
547+ // because libgit2 doesn't support local shallow clones.
548+ // https://github.com/rust-lang/git2-rs/pull/979#issuecomment-1716299900
549+ pub fn depth ( & mut self , depth : i32 ) -> & mut Self {
550+ self . depth = depth. max ( 0 ) ;
551+ self
552+ }
553+
541554 /// Set how to behave regarding tags on the remote, such as auto-downloading
542555 /// tags for objects we're downloading or downloading all of them.
543556 ///
@@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
590603 prune : crate :: call:: convert ( & self . prune ) ,
591604 update_fetchhead : crate :: call:: convert ( & self . update_fetchhead ) ,
592605 download_tags : crate :: call:: convert ( & self . download_tags ) ,
593- depth : 0 , // GIT_FETCH_DEPTH_FULL.
606+ depth : self . depth ,
594607 follow_redirects : self . follow_redirects . raw ( ) ,
595608 custom_headers : git_strarray {
596609 count : self . custom_headers_ptrs . len ( ) ,
0 commit comments