@@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> {
41
41
/// Options which can be specified to various fetch operations.
42
42
pub struct FetchOptions < ' cb > {
43
43
callbacks : Option < RemoteCallbacks < ' cb > > ,
44
+ depth : i32 ,
44
45
proxy : Option < ProxyOptions < ' cb > > ,
45
46
prune : FetchPrune ,
46
47
update_fetchhead : bool ,
@@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> {
509
510
follow_redirects : RemoteRedirect :: Initial ,
510
511
custom_headers : Vec :: new ( ) ,
511
512
custom_headers_ptrs : Vec :: new ( ) ,
513
+ depth : 0 , // Not limited depth
512
514
}
513
515
}
514
516
@@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> {
538
540
self
539
541
}
540
542
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
+
541
554
/// Set how to behave regarding tags on the remote, such as auto-downloading
542
555
/// tags for objects we're downloading or downloading all of them.
543
556
///
@@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
590
603
prune : crate :: call:: convert ( & self . prune ) ,
591
604
update_fetchhead : crate :: call:: convert ( & self . update_fetchhead ) ,
592
605
download_tags : crate :: call:: convert ( & self . download_tags ) ,
593
- depth : 0 , // GIT_FETCH_DEPTH_FULL.
606
+ depth : self . depth ,
594
607
follow_redirects : self . follow_redirects . raw ( ) ,
595
608
custom_headers : git_strarray {
596
609
count : self . custom_headers_ptrs . len ( ) ,
0 commit comments