@@ -4,6 +4,7 @@ use cargo_test_support::{basic_manifest, git, paths, project};
44
55use crate :: git_gc:: find_index;
66
7+ #[ derive( Copy , Clone , Debug ) ]
78enum Backend {
89 Git2 ,
910 Gitoxide ,
@@ -28,6 +29,7 @@ impl Backend {
2829 }
2930}
3031
32+ #[ derive( Copy , Clone , Debug ) ]
3133enum RepoMode {
3234 Shallow ,
3335 Complete ,
@@ -47,6 +49,27 @@ impl RepoMode {
4749 RepoMode :: Shallow => "-Zgit=shallow-index" ,
4850 }
4951 }
52+
53+ #[ track_caller]
54+ fn assert_index ( self , repo : & gix:: Repository , shallow_depth : usize , complete_depth : usize ) {
55+ let commit_count = repo
56+ . rev_parse_single ( "origin/HEAD" )
57+ . unwrap ( )
58+ . ancestors ( )
59+ . all ( )
60+ . unwrap ( )
61+ . count ( ) ;
62+ match self {
63+ RepoMode :: Shallow => {
64+ assert_eq ! ( commit_count, shallow_depth, ) ;
65+ assert ! ( repo. is_shallow( ) ) ;
66+ }
67+ RepoMode :: Complete => {
68+ assert_eq ! ( commit_count, complete_depth, ) ;
69+ assert ! ( !repo. is_shallow( ) ) ;
70+ }
71+ }
72+ }
5073}
5174
5275#[ cargo_test]
@@ -313,17 +336,29 @@ fn fetch_shallow_dep_branch_to_rev(backend: Backend) -> anyhow::Result<()> {
313336
314337#[ cargo_test]
315338fn gitoxide_fetch_shallow_index_then_git2_fetch_complete ( ) -> anyhow:: Result < ( ) > {
316- fetch_shallow_index_then_fetch_complete ( Backend :: Gitoxide , Backend :: Git2 )
339+ fetch_index_then_fetch (
340+ Backend :: Gitoxide ,
341+ RepoMode :: Shallow ,
342+ Backend :: Git2 ,
343+ RepoMode :: Complete ,
344+ )
317345}
318346
319347#[ cargo_test]
320348fn git_cli_fetch_shallow_index_then_git2_fetch_complete ( ) -> anyhow:: Result < ( ) > {
321- fetch_shallow_index_then_fetch_complete ( Backend :: GitCli , Backend :: Git2 )
349+ fetch_index_then_fetch (
350+ Backend :: GitCli ,
351+ RepoMode :: Shallow ,
352+ Backend :: Git2 ,
353+ RepoMode :: Complete ,
354+ )
322355}
323356
324- fn fetch_shallow_index_then_fetch_complete (
357+ fn fetch_index_then_fetch (
325358 backend_1st : Backend ,
359+ mode_1st : RepoMode ,
326360 backend_2nd : Backend ,
361+ mode_2nd : RepoMode ,
327362) -> anyhow:: Result < ( ) > {
328363 Package :: new ( "bar" , "1.0.0" ) . publish ( ) ;
329364 let p = project ( )
@@ -342,47 +377,31 @@ fn fetch_shallow_index_then_fetch_complete(
342377 . build ( ) ;
343378 p. cargo ( "fetch" )
344379 . arg_line ( backend_1st. to_arg ( ) )
345- . arg ( RepoMode :: Shallow . to_index_arg ( ) )
380+ . arg_line ( mode_1st . to_index_arg ( ) )
346381 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
347382 . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-index" ] )
348383 . env ( "CARGO_LOG" , "git-fetch=debug" )
349384 . with_stderr_contains ( backend_1st. to_trace_log ( ) )
350385 . run ( ) ;
351386
352- let shallow_repo = gix:: open_opts ( find_index ( ) , gix:: open:: Options :: isolated ( ) ) ?;
353- assert_eq ! (
354- shallow_repo
355- . rev_parse_single( "origin/HEAD" ) ?
356- . ancestors( )
357- . all( ) ?
358- . count( ) ,
359- 1 ,
360- "shallow fetch always start at depth of 1 to minimize download size"
361- ) ;
362- assert ! ( shallow_repo. is_shallow( ) ) ;
387+ let repo = gix:: open_opts ( find_remote_index ( mode_1st) , gix:: open:: Options :: isolated ( ) ) ?;
388+ let complete_depth =
2 ; // initial commmit, [email protected] 389+ mode_1st. assert_index ( & repo, 1 , complete_depth) ;
363390
364391 Package :: new ( "bar" , "1.1.0" ) . publish ( ) ;
365392 p. cargo ( "update" )
366393 . arg_line ( backend_2nd. to_arg ( ) )
394+ . arg_line ( mode_2nd. to_index_arg ( ) )
367395 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
368- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" ] )
396+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-index" ] )
369397 . env ( "CARGO_LOG" , "git-fetch=debug" )
370398 . with_stderr_contains ( backend_2nd. to_trace_log ( ) )
371399 . run ( ) ;
372400
373- let repo = gix:: open_opts (
374- find_remote_index ( RepoMode :: Complete ) ,
375- gix:: open:: Options :: isolated ( ) ,
376- ) ?;
377- assert_eq ! (
378- repo. rev_parse_single( "origin/HEAD" ) ?
379- . ancestors( )
380- . all( ) ?
381- . count( ) ,
382- 3 ,
383- "an entirely new repo was fetched which is never shallow"
384- ) ;
385- assert ! ( !repo. is_shallow( ) ) ;
401+ let repo = gix:: open_opts ( find_remote_index ( mode_2nd) , gix:: open:: Options :: isolated ( ) ) ?;
402+ let complete_depth =
3 ; // initial commmit, [email protected] , and [email protected] 403+ mode_2nd. assert_index ( & repo, 1 , complete_depth) ;
404+
386405 Ok ( ( ) )
387406}
388407
0 commit comments