@@ -540,8 +540,12 @@ impl<'cb> FetchOptions<'cb> {
540
540
self
541
541
}
542
542
543
- /// Set fetch depth, a value less than zero is interpreted as pull everything (effectively the same as no declaring a limit depth)
543
+ /// Set fetch depth, a value less or equal to 0 is interpreted as pull everything (effectively the same as not declaring a limit depth)
544
544
pub fn depth ( & mut self , depth : i32 ) -> & mut Self {
545
+ if depth. is_negative ( ) {
546
+ self . depth = 0 ;
547
+ return self ;
548
+ }
545
549
self . depth = depth;
546
550
self
547
551
}
@@ -752,6 +756,7 @@ impl RemoteRedirect {
752
756
753
757
#[ cfg( test) ]
754
758
mod tests {
759
+ use crate :: build:: RepoBuilder ;
755
760
use crate :: { AutotagOption , PushOptions } ;
756
761
use crate :: { Direction , FetchOptions , Remote , RemoteCallbacks , Repository } ;
757
762
use std:: cell:: Cell ;
@@ -1115,4 +1120,43 @@ mod tests {
1115
1120
assert_eq ! ( flag, 7 ) ;
1116
1121
assert_eq ! ( remote_repo. branches( None ) . unwrap( ) . count( ) , 3 ) ;
1117
1122
}
1123
+
1124
+ #[ test]
1125
+ fn shallow_clone ( ) {
1126
+ let ( td, repo) = crate :: test:: repo_init ( ) ;
1127
+
1128
+ let commit = repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
1129
+ let first_commit = repo. find_commit ( commit) . unwrap ( ) ;
1130
+
1131
+ let sig = repo. signature ( ) . unwrap ( ) ;
1132
+ let mut index = repo. index ( ) . unwrap ( ) ;
1133
+ let tree = index. write_tree ( ) . unwrap ( ) ;
1134
+ let tree = repo. find_tree ( tree) . unwrap ( ) ;
1135
+
1136
+ let second_commit = repo. commit (
1137
+ Some ( "HEAD" ) ,
1138
+ & sig,
1139
+ & sig,
1140
+ "second commit" ,
1141
+ & tree,
1142
+ & [ & first_commit]
1143
+ ) . unwrap ( ) ;
1144
+
1145
+ let td2 = TempDir :: new ( ) . unwrap ( ) ;
1146
+ let mut fo = FetchOptions :: new ( ) ;
1147
+ fo. depth ( 1 ) ;
1148
+
1149
+ let new_repo = RepoBuilder :: new ( )
1150
+ . fetch_options ( fo)
1151
+ . clone ( & td. into_path ( ) . as_os_str ( ) . to_str ( ) . unwrap ( ) , td2. path ( ) )
1152
+ . unwrap ( ) ;
1153
+
1154
+ dbg ! ( new_repo. is_shallow( ) ) ;
1155
+
1156
+ let _ = dbg ! ( new_repo. find_commit( first_commit. id( ) ) ) ; // ????
1157
+ let _ = dbg ! ( new_repo. find_commit( second_commit) ) ;
1158
+
1159
+ // Check that there's only one commit
1160
+ panic ! ( ) ;
1161
+ }
1118
1162
}
0 commit comments