@@ -14,6 +14,7 @@ mod shallow {
14
14
mod blocking_and_async_io {
15
15
use std:: sync:: atomic:: AtomicBool ;
16
16
17
+ use gix:: remote:: fetch:: Status ;
17
18
use gix:: remote:: { fetch, Direction :: Fetch } ;
18
19
use gix_features:: progress;
19
20
use gix_protocol:: maybe_async;
@@ -43,10 +44,32 @@ mod blocking_and_async_io {
43
44
#[ allow( clippy:: result_large_err) ]
44
45
pub ( crate ) fn try_repo_rw (
45
46
name : & str ,
47
+ ) -> Result < ( gix:: Repository , gix_testtools:: tempfile:: TempDir ) , gix:: open:: Error > {
48
+ try_repo_rw_args ( name, Vec :: < String > :: new ( ) , Mode :: FastClone )
49
+ }
50
+
51
+ pub ( crate ) enum Mode {
52
+ FastClone ,
53
+ CloneWithShallowSupport ,
54
+ }
55
+
56
+ #[ allow( clippy:: result_large_err) ]
57
+ pub ( crate ) fn try_repo_rw_args < S : Into < String > > (
58
+ name : & str ,
59
+ args : impl IntoIterator < Item = S > ,
60
+ mode : Mode ,
46
61
) -> Result < ( gix:: Repository , gix_testtools:: tempfile:: TempDir ) , gix:: open:: Error > {
47
62
let dir = gix_testtools:: scripted_fixture_writable_with_args (
48
63
"make_fetch_repos.sh" ,
49
- [ base_repo_path ( ) ] ,
64
+ [ {
65
+ let mut url = base_repo_path ( ) ;
66
+ if matches ! ( mode, Mode :: CloneWithShallowSupport ) {
67
+ url. insert_str ( 0 , "file://" ) ;
68
+ }
69
+ url
70
+ } ]
71
+ . into_iter ( )
72
+ . chain ( args. into_iter ( ) . map ( Into :: into) ) ,
50
73
gix_testtools:: Creation :: ExecuteScript ,
51
74
)
52
75
. unwrap ( ) ;
@@ -84,6 +107,58 @@ mod blocking_and_async_io {
84
107
Ok ( ( ) )
85
108
}
86
109
110
+ #[ maybe_async:: test(
111
+ feature = "blocking-network-client" ,
112
+ async ( feature = "async-network-client-async-std" , async_std:: test)
113
+ ) ]
114
+ async fn fetch_shallow_deepen_not_possible ( ) -> crate :: Result {
115
+ let ( repo, _tmp) = try_repo_rw_args ( "two-origins" , [ "--depth=2" ] , Mode :: CloneWithShallowSupport ) ?;
116
+ let remote = repo
117
+ . head ( ) ?
118
+ . into_remote ( Fetch )
119
+ . expect ( "present" ) ?
120
+ . with_fetch_tags ( fetch:: Tags :: Included ) ;
121
+
122
+ assert_eq ! (
123
+ repo. shallow_commits( ) ?. expect( "shallow clone" ) . as_slice( ) ,
124
+ [
125
+ hex_to_id( "2d9d136fb0765f2e24c44a0f91984318d580d03b" ) ,
126
+ hex_to_id( "dfd0954dabef3b64f458321ef15571cc1a46d552" ) ,
127
+ hex_to_id( "dfd0954dabef3b64f458321ef15571cc1a46d552" )
128
+ ]
129
+ ) ;
130
+ let prev_commits = repo. head_id ( ) ?. ancestors ( ) . all ( ) ?. count ( ) ;
131
+ let changes = remote
132
+ . connect ( Fetch , gix:: progress:: Discard )
133
+ . await ?
134
+ . prepare_fetch ( Default :: default ( ) )
135
+ . await ?
136
+ . with_shallow ( fetch:: Shallow :: Deepen ( 1 ) )
137
+ . receive ( & AtomicBool :: default ( ) )
138
+ . await ?;
139
+
140
+ assert ! (
141
+ matches!( changes. status, Status :: Change { write_pack_bundle, ..} if write_pack_bundle. index. num_objects == 0 ) ,
142
+ "we get an empty pack as there is nothing to do"
143
+ ) ;
144
+
145
+ assert_eq ! (
146
+ repo. shallow_commits( ) ?. expect( "shallow clone" ) . as_slice( ) ,
147
+ [
148
+ hex_to_id( "2d9d136fb0765f2e24c44a0f91984318d580d03b" ) ,
149
+ hex_to_id( "dfd0954dabef3b64f458321ef15571cc1a46d552" ) ,
150
+ hex_to_id( "dfd0954dabef3b64f458321ef15571cc1a46d552" )
151
+ ] ,
152
+ "the base is shallow, and so is the clone, and we can't extend further"
153
+ ) ;
154
+ assert_eq ! (
155
+ repo. head_id( ) ?. ancestors( ) . all( ) ?. count( ) ,
156
+ prev_commits,
157
+ "no more commits are available - there simply isn't more information"
158
+ ) ;
159
+ Ok ( ( ) )
160
+ }
161
+
87
162
#[ maybe_async:: test(
88
163
feature = "blocking-network-client" ,
89
164
async ( feature = "async-network-client-async-std" , async_std:: test)
0 commit comments