@@ -278,10 +278,13 @@ fn fetch_shallow_dep_branch_to_rev(backend: Backend) -> anyhow::Result<()> {
278278
279279#[ cargo_test]
280280fn gitoxide_fetch_shallow_index_then_git2_fetch_complete ( ) -> anyhow:: Result < ( ) > {
281- fetch_shallow_index_then_git2_fetch_complete ( Backend :: Gitoxide )
281+ fetch_shallow_index_then_fetch_complete ( Backend :: Gitoxide , Backend :: Git2 )
282282}
283283
284- fn fetch_shallow_index_then_git2_fetch_complete ( backend : Backend ) -> anyhow:: Result < ( ) > {
284+ fn fetch_shallow_index_then_fetch_complete (
285+ backend_1st : Backend ,
286+ backend_2nd : Backend ,
287+ ) -> anyhow:: Result < ( ) > {
285288 Package :: new ( "bar" , "1.0.0" ) . publish ( ) ;
286289 let p = project ( )
287290 . file (
@@ -298,7 +301,7 @@ fn fetch_shallow_index_then_git2_fetch_complete(backend: Backend) -> anyhow::Res
298301 . file ( "src/lib.rs" , "" )
299302 . build ( ) ;
300303 p. cargo ( "fetch" )
301- . arg_line ( backend . to_arg ( ) )
304+ . arg_line ( backend_1st . to_arg ( ) )
302305 . arg ( "-Zgit=shallow-index" )
303306 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
304307 . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-index" ] )
@@ -318,7 +321,9 @@ fn fetch_shallow_index_then_git2_fetch_complete(backend: Backend) -> anyhow::Res
318321
319322 Package :: new ( "bar" , "1.1.0" ) . publish ( ) ;
320323 p. cargo ( "update" )
324+ . arg_line ( backend_2nd. to_arg ( ) )
321325 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
326+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" ] )
322327 . run ( ) ;
323328
324329 let repo = gix:: open_opts (
@@ -339,10 +344,18 @@ fn fetch_shallow_index_then_git2_fetch_complete(backend: Backend) -> anyhow::Res
339344
340345#[ cargo_test]
341346fn gitoxide_fetch_shallow_dep_then_git2_fetch_complete ( ) -> anyhow:: Result < ( ) > {
342- fetch_shallow_dep_then_git2_fetch_complete ( Backend :: Gitoxide )
347+ fetch_shallow_dep_then_fetch_complete ( Backend :: Gitoxide , Backend :: Git2 )
343348}
344349
345- fn fetch_shallow_dep_then_git2_fetch_complete ( backend : Backend ) -> anyhow:: Result < ( ) > {
350+ #[ cargo_test]
351+ fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete ( ) -> anyhow:: Result < ( ) > {
352+ fetch_shallow_dep_then_fetch_complete ( Backend :: Gitoxide , Backend :: Gitoxide )
353+ }
354+
355+ fn fetch_shallow_dep_then_fetch_complete (
356+ backend_1st : Backend ,
357+ backend_2nd : Backend ,
358+ ) -> anyhow:: Result < ( ) > {
346359 // Example where an old lockfile with an explicit branch="master" in Cargo.toml.
347360 Package :: new ( "bar" , "1.0.0" ) . publish ( ) ;
348361 let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
@@ -383,7 +396,7 @@ fn fetch_shallow_dep_then_git2_fetch_complete(backend: Backend) -> anyhow::Resul
383396 . build ( ) ;
384397
385398 p. cargo ( "update" )
386- . arg_line ( backend . to_arg ( ) )
399+ . arg_line ( backend_1st . to_arg ( ) )
387400 . arg_line ( RepoMode :: Shallow . to_deps_arg ( ) )
388401 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
389402 . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
@@ -429,7 +442,9 @@ fn fetch_shallow_dep_then_git2_fetch_complete(backend: Backend) -> anyhow::Resul
429442 }
430443
431444 p. cargo ( "update" )
445+ . arg_line ( backend_2nd. to_arg ( ) )
432446 . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
447+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" ] )
433448 . run ( ) ;
434449
435450 let db_clone = gix:: open_opts (
@@ -479,151 +494,6 @@ fn fetch_shallow_dep_then_git2_fetch_complete(backend: Backend) -> anyhow::Resul
479494 Ok ( ( ) )
480495}
481496
482- #[ cargo_test]
483- fn gitoxide_fetch_shallow_dep_then_gitoxide_fetch_complete ( ) -> anyhow:: Result < ( ) > {
484- fetch_shallow_dep_then_gitoxide_fetch_complete ( Backend :: Gitoxide )
485- }
486-
487- fn fetch_shallow_dep_then_gitoxide_fetch_complete ( backend : Backend ) -> anyhow:: Result < ( ) > {
488- Package :: new ( "bar" , "1.0.0" ) . publish ( ) ;
489- let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
490- p. file ( "Cargo.toml" , & basic_manifest ( "bar" , "1.0.0" ) )
491- . file ( "src/lib.rs" , "" )
492- } ) ;
493-
494- bar. change_file ( "src/lib.rs" , "// change" ) ;
495- git:: add ( & bar_repo) ;
496- git:: commit ( & bar_repo) ;
497-
498- {
499- let mut walk = bar_repo. revwalk ( ) ?;
500- walk. push_head ( ) ?;
501- assert_eq ! (
502- walk. count( ) ,
503- 2 ,
504- "original repo has initial commit and change commit"
505- ) ;
506- }
507-
508- let p = project ( )
509- . file (
510- "Cargo.toml" ,
511- & format ! (
512- r#"
513- [package]
514- name = "foo"
515- version = "0.1.0"
516-
517- [dependencies]
518- bar = {{ version = "1.0", git = "{}", branch = "master" }}
519- "# ,
520- bar. url( )
521- ) ,
522- )
523- . file ( "src/lib.rs" , "" )
524- . build ( ) ;
525-
526- p. cargo ( "update" )
527- . arg_line ( backend. to_arg ( ) )
528- . arg_line ( RepoMode :: Shallow . to_deps_arg ( ) )
529- . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
530- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
531- . run ( ) ;
532-
533- let shallow_db_clone = gix:: open_opts (
534- find_bar_db ( RepoMode :: Shallow ) ,
535- gix:: open:: Options :: isolated ( ) ,
536- ) ?;
537- assert ! ( shallow_db_clone. is_shallow( ) ) ;
538- assert_eq ! (
539- shallow_db_clone
540- . rev_parse_single( "origin/master" ) ?
541- . ancestors( )
542- . all( ) ?
543- . count( ) ,
544- 1 ,
545- "db fetches are shallow and have a shortened history"
546- ) ;
547-
548- let dep_checkout = gix:: open_opts (
549- find_lexicographically_first_bar_checkout ( ) ,
550- gix:: open:: Options :: isolated ( ) ,
551- ) ?;
552- assert ! ( dep_checkout. is_shallow( ) ) ;
553- assert_eq ! (
554- dep_checkout. head_id( ) ?. ancestors( ) . all( ) ?. count( ) ,
555- 1 ,
556- "db checkouts are hard-linked fetches with the shallow file copied separately."
557- ) ;
558-
559- bar. change_file ( "src/lib.rs" , "// another change" ) ;
560- git:: add ( & bar_repo) ;
561- git:: commit ( & bar_repo) ;
562- {
563- let mut walk = bar_repo. revwalk ( ) ?;
564- walk. push_head ( ) ?;
565- assert_eq ! (
566- walk. count( ) ,
567- 3 ,
568- "original repo has initial commit and change commit, and another change"
569- ) ;
570- }
571-
572- p. cargo ( "update" )
573- . arg_line ( Backend :: Gitoxide . to_arg ( ) ) // shallow-deps is omitted intentionally
574- . env ( "__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2" , "0" )
575- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" ] )
576- . run ( ) ;
577-
578- let db_clone = gix:: open_opts (
579- find_bar_db ( RepoMode :: Complete ) ,
580- gix:: open:: Options :: isolated ( ) ,
581- ) ?;
582- assert_eq ! (
583- db_clone
584- . rev_parse_single( "origin/master" ) ?
585- . ancestors( )
586- . all( ) ?
587- . count( ) ,
588- 3 ,
589- "we created an entirely new non-shallow clone"
590- ) ;
591- assert ! ( !db_clone. is_shallow( ) ) ;
592- assert_eq ! (
593- dep_checkout. head_id( ) ?. ancestors( ) . all( ) ?. count( ) ,
594- 1 ,
595- "the original dep checkout didn't change - there is a new one for each update we get locally"
596- ) ;
597-
598- let max_history_depth = glob:: glob (
599- paths:: home ( )
600- . join ( ".cargo/git/checkouts/bar-*/*/.git" )
601- . to_str ( )
602- . unwrap ( ) ,
603- ) ?
604- . map ( |path| -> anyhow:: Result < usize > {
605- let path = path?;
606- let dep_checkout = gix:: open_opts ( & path, gix:: open:: Options :: isolated ( ) ) ?;
607- assert_eq ! (
608- dep_checkout. is_shallow( ) ,
609- path. to_string_lossy( ) . contains( "-shallow" ) ,
610- "checkouts of shallow db repos are shallow as well"
611- ) ;
612- let depth = dep_checkout. head_id ( ) ?. ancestors ( ) . all ( ) ?. count ( ) ;
613- Ok ( depth)
614- } )
615- . map ( Result :: unwrap)
616- . max ( )
617- . expect ( "two checkout repos" ) ;
618-
619- assert_eq ! (
620- max_history_depth, 3 ,
621- "we see the previous shallow checkout as well as new unshallow one"
622- ) ;
623-
624- Ok ( ( ) )
625- }
626-
627497#[ cargo_test]
628498fn gitoxide_fetch_shallow_index_then_preserve_shallow ( ) -> anyhow:: Result < ( ) > {
629499 fetch_shallow_index_then_preserve_shallow ( Backend :: Gitoxide )
0 commit comments