@@ -1868,30 +1868,31 @@ fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_with_git2_fetch(
1868
1868
. masquerade_as_nightly_cargo ( & [ "unstable features must be available for -Z gitoxide" ] )
1869
1869
. run ( ) ;
1870
1870
1871
- let repo = gix:: open_opts ( find_index ( ) , gix:: open:: Options :: isolated ( ) ) ?;
1871
+ let shallow_repo = gix:: open_opts ( find_index ( ) , gix:: open:: Options :: isolated ( ) ) ?;
1872
1872
assert_eq ! (
1873
- repo. rev_parse_single( "origin/HEAD" ) ?
1873
+ shallow_repo
1874
+ . rev_parse_single( "origin/HEAD" ) ?
1874
1875
. ancestors( )
1875
1876
. all( ) ?
1876
1877
. count( ) ,
1877
1878
1 ,
1878
1879
"shallow clones always start at depth of 1 to minimize download size"
1879
1880
) ;
1880
- assert ! ( repo . is_shallow( ) ) ;
1881
+ assert ! ( shallow_repo . is_shallow( ) ) ;
1881
1882
1882
1883
Package :: new ( "bar" , "1.1.0" ) . publish ( ) ;
1883
1884
p. cargo ( "update" )
1884
1885
. env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
1885
1886
. run ( ) ;
1886
1887
1888
+ let repo = gix:: open_opts ( find_remote_index ( false ) , gix:: open:: Options :: isolated ( ) ) ?;
1887
1889
assert_eq ! (
1888
1890
repo. rev_parse_single( "origin/HEAD" ) ?
1889
1891
. ancestors( )
1890
1892
. all( ) ?
1891
1893
. count( ) ,
1892
1894
3 ,
1893
- "the repo was forcefully reinitialized and fetch again with full history - that way we take control and know the state of the repo \
1894
- instead of allowing a non-shallow aware implementation to cause trouble later"
1895
+ "an entirely new repo was cloned which is never shallow"
1895
1896
) ;
1896
1897
assert ! ( !repo. is_shallow( ) ) ;
1897
1898
Ok ( ( ) )
@@ -2220,7 +2221,7 @@ fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_fetch_maintains_
2220
2221
2221
2222
Package :: new ( "bar" , "1.1.0" ) . publish ( ) ;
2222
2223
p. cargo ( "update" )
2223
- . arg ( "-Zgitoxide=fetch" ) // NOTE: intentionally missing shallow flag
2224
+ . arg ( "-Zgitoxide=fetch,shallow-index " ) // NOTE: the flag needs to be consistent or else a different index is created
2224
2225
. masquerade_as_nightly_cargo ( & [ "unstable features must be available for -Z gitoxide" ] )
2225
2226
. run ( ) ;
2226
2227
@@ -2254,6 +2255,20 @@ fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_fetch_maintains_
2254
2255
Ok ( ( ) )
2255
2256
}
2256
2257
2258
+ pub fn find_remote_index ( shallow : bool ) -> std:: path:: PathBuf {
2259
+ glob:: glob (
2260
+ paths:: home ( )
2261
+ . join ( ".cargo/registry/index/*" )
2262
+ . to_str ( )
2263
+ . unwrap ( ) ,
2264
+ )
2265
+ . unwrap ( )
2266
+ . map ( Result :: unwrap)
2267
+ . filter ( |p| p. to_string_lossy ( ) . ends_with ( "-shallow" ) == shallow)
2268
+ . next ( )
2269
+ . unwrap ( )
2270
+ }
2271
+
2257
2272
#[ cargo_test]
2258
2273
fn gitoxide_clones_registry_without_shallow_protocol_and_follow_up_fetch_uses_shallowness (
2259
2274
) -> anyhow:: Result < ( ) > {
@@ -2294,15 +2309,16 @@ fn gitoxide_clones_registry_without_shallow_protocol_and_follow_up_fetch_uses_sh
2294
2309
. masquerade_as_nightly_cargo ( & [ "unstable features must be available for -Z gitoxide" ] )
2295
2310
. run ( ) ;
2296
2311
2312
+ let shallow_repo = gix:: open_opts ( find_remote_index ( true ) , gix:: open:: Options :: isolated ( ) ) ?;
2297
2313
assert_eq ! (
2298
- repo . rev_parse_single( "origin/HEAD" ) ?
2314
+ shallow_repo . rev_parse_single( "origin/HEAD" ) ?
2299
2315
. ancestors( )
2300
2316
. all( ) ?
2301
2317
. count( ) ,
2302
2318
1 ,
2303
- "follow- up fetches maintain can shallow an existing unshallow repo - this doesn't have any benefit as we still have the objects locally "
2319
+ "the follow up clones an entirely new index which is now shallow and which is in its own location "
2304
2320
) ;
2305
- assert ! ( repo . is_shallow( ) ) ;
2321
+ assert ! ( shallow_repo . is_shallow( ) ) ;
2306
2322
2307
2323
Package :: new ( "bar" , "1.2.0" ) . publish ( ) ;
2308
2324
Package :: new ( "bar" , "1.3.0" ) . publish ( ) ;
@@ -2312,14 +2328,28 @@ fn gitoxide_clones_registry_without_shallow_protocol_and_follow_up_fetch_uses_sh
2312
2328
. run ( ) ;
2313
2329
2314
2330
assert_eq ! (
2315
- repo . rev_parse_single( "origin/HEAD" ) ?
2331
+ shallow_repo . rev_parse_single( "origin/HEAD" ) ?
2316
2332
. ancestors( )
2317
2333
. all( ) ?
2318
2334
. count( ) ,
2319
2335
3 ,
2320
2336
"even if depth (at remote) is specified again, the current shallow boundary is maintained and not moved"
2321
2337
) ;
2322
- assert ! ( repo. is_shallow( ) ) ;
2338
+ assert ! ( shallow_repo. is_shallow( ) ) ;
2339
+
2340
+ p. cargo ( "update" )
2341
+ . arg ( "-Zgitoxide=fetch" )
2342
+ . masquerade_as_nightly_cargo ( & [ "unstable features must be available for -Z gitoxide" ] )
2343
+ . run ( ) ;
2344
+
2345
+ assert_eq ! (
2346
+ repo. rev_parse_single( "origin/HEAD" ) ?
2347
+ . ancestors( )
2348
+ . all( ) ?
2349
+ . count( ) ,
2350
+ 5 ,
2351
+ "we can separately fetch the non-shallow index as well and it sees all commits"
2352
+ ) ;
2323
2353
2324
2354
Ok ( ( ) )
2325
2355
}
0 commit comments