@@ -128,6 +128,143 @@ fn fetch_two_revs_same_deps(backend: Backend, mode: RepoMode) {
128128 . run ( ) ;
129129}
130130
131+ #[ cargo_test]
132+ fn shallow_deps_work_with_revisions_and_branches_mixed_on_same_dependency ( ) -> anyhow:: Result < ( ) > {
133+ let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
134+ p. file ( "Cargo.toml" , & basic_manifest ( "bar" , "1.0.0" ) )
135+ . file ( "src/lib.rs" , "" )
136+ } ) ;
137+
138+ // this commit would not be available in a shallow fetch.
139+ let first_commit_pre_change = bar_repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
140+
141+ bar. change_file ( "src/lib.rs" , "// change" ) ;
142+ git:: add ( & bar_repo) ;
143+ git:: commit ( & bar_repo) ;
144+
145+ let p = project ( )
146+ . file (
147+ "Cargo.toml" ,
148+ & format ! (
149+ r#"
150+ [package]
151+ name = "foo"
152+ version = "0.1.0"
153+
154+ [dependencies]
155+ bar-renamed = {{ package = "bar", git = "{}", rev = "{}" }}
156+ bar = {{ git = "{}", branch = "master" }}
157+ "# ,
158+ bar. url( ) ,
159+ first_commit_pre_change,
160+ bar. url( ) ,
161+ ) ,
162+ )
163+ . file ( "src/lib.rs" , "" )
164+ . build ( ) ;
165+
166+ p. cargo ( "check" )
167+ . arg ( "-Zgitoxide=fetch" )
168+ . arg ( "-Zgit=shallow-deps" )
169+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
170+ . run ( ) ;
171+
172+ let db_paths = glob:: glob ( paths:: home ( ) . join ( ".cargo/git/db/bar-*" ) . to_str ( ) . unwrap ( ) ) ?
173+ . map ( Result :: unwrap)
174+ . collect :: < Vec < _ > > ( ) ;
175+ assert_eq ! (
176+ db_paths. len( ) ,
177+ 1 ,
178+ "only one db checkout source is used per dependency"
179+ ) ;
180+ let db_clone = gix:: open_opts ( & db_paths[ 0 ] , gix:: open:: Options :: isolated ( ) ) ?;
181+ assert ! (
182+ db_clone. is_shallow( ) ,
183+ "the repo is shallow while having all data it needs"
184+ ) ;
185+
186+ Ok ( ( ) )
187+ }
188+
189+ #[ cargo_test]
190+ fn gitoxide_git_dependencies_switch_from_branch_to_rev ( ) -> anyhow:: Result < ( ) > {
191+ // db exists from previous build, then dependency changes to refer to revision that isn't
192+ // available in the shallow fetch.
193+
194+ let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
195+ p. file ( "Cargo.toml" , & basic_manifest ( "bar" , "1.0.0" ) )
196+ . file ( "src/lib.rs" , "" )
197+ } ) ;
198+
199+ // this commit would not be available in a shallow fetch.
200+ let first_commit_pre_change = bar_repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
201+
202+ bar. change_file ( "src/lib.rs" , "// change" ) ;
203+ git:: add ( & bar_repo) ;
204+ git:: commit ( & bar_repo) ;
205+ let p = project ( )
206+ . file (
207+ "Cargo.toml" ,
208+ & format ! (
209+ r#"
210+ [package]
211+ name = "foo"
212+ version = "0.1.0"
213+
214+ [dependencies]
215+ bar = {{ git = "{}", branch = "master" }}
216+ "# ,
217+ bar. url( ) ,
218+ ) ,
219+ )
220+ . file ( "src/lib.rs" , "" )
221+ . build ( ) ;
222+
223+ p. cargo ( "check" )
224+ . arg ( "-Zgitoxide=fetch" )
225+ . arg ( "-Zgit=shallow-deps" )
226+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
227+ . run ( ) ;
228+
229+ let db_clone = gix:: open_opts (
230+ find_bar_db ( RepoMode :: Shallow ) ,
231+ gix:: open:: Options :: isolated ( ) ,
232+ ) ?;
233+ assert ! ( db_clone. is_shallow( ) ) ;
234+
235+ let p = project ( )
236+ . file (
237+ "Cargo.toml" ,
238+ & format ! (
239+ r#"
240+ [package]
241+ name = "foo"
242+ version = "0.1.0"
243+
244+ [dependencies]
245+ bar = {{ git = "{}", rev = "{}" }}
246+ "# ,
247+ bar. url( ) ,
248+ first_commit_pre_change
249+ ) ,
250+ )
251+ . file ( "src/lib.rs" , "" )
252+ . build ( ) ;
253+
254+ p. cargo ( "check" )
255+ . arg ( "-Zgitoxide=fetch" )
256+ . arg ( "-Zgit=shallow-deps" )
257+ . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
258+ . run ( ) ;
259+
260+ assert ! (
261+ db_clone. is_shallow( ) ,
262+ "we maintain shallowness and never unshallow"
263+ ) ;
264+
265+ Ok ( ( ) )
266+ }
267+
131268#[ cargo_test]
132269fn gitoxide_fetch_registry_with_shallow_protocol_and_follow_up_with_git2_fetch (
133270) -> anyhow:: Result < ( ) > {
@@ -627,143 +764,6 @@ fn gitoxide_fetch_registry_without_shallow_protocol_and_follow_up_fetch_uses_sha
627764 Ok ( ( ) )
628765}
629766
630- #[ cargo_test]
631- fn gitoxide_git_dependencies_switch_from_branch_to_rev ( ) -> anyhow:: Result < ( ) > {
632- // db exists from previous build, then dependency changes to refer to revision that isn't
633- // available in the shallow fetch.
634-
635- let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
636- p. file ( "Cargo.toml" , & basic_manifest ( "bar" , "1.0.0" ) )
637- . file ( "src/lib.rs" , "" )
638- } ) ;
639-
640- // this commit would not be available in a shallow fetch.
641- let first_commit_pre_change = bar_repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
642-
643- bar. change_file ( "src/lib.rs" , "// change" ) ;
644- git:: add ( & bar_repo) ;
645- git:: commit ( & bar_repo) ;
646- let p = project ( )
647- . file (
648- "Cargo.toml" ,
649- & format ! (
650- r#"
651- [package]
652- name = "foo"
653- version = "0.1.0"
654-
655- [dependencies]
656- bar = {{ git = "{}", branch = "master" }}
657- "# ,
658- bar. url( ) ,
659- ) ,
660- )
661- . file ( "src/lib.rs" , "" )
662- . build ( ) ;
663-
664- p. cargo ( "check" )
665- . arg ( "-Zgitoxide=fetch" )
666- . arg ( "-Zgit=shallow-deps" )
667- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
668- . run ( ) ;
669-
670- let db_clone = gix:: open_opts (
671- find_bar_db ( RepoMode :: Shallow ) ,
672- gix:: open:: Options :: isolated ( ) ,
673- ) ?;
674- assert ! ( db_clone. is_shallow( ) ) ;
675-
676- let p = project ( )
677- . file (
678- "Cargo.toml" ,
679- & format ! (
680- r#"
681- [package]
682- name = "foo"
683- version = "0.1.0"
684-
685- [dependencies]
686- bar = {{ git = "{}", rev = "{}" }}
687- "# ,
688- bar. url( ) ,
689- first_commit_pre_change
690- ) ,
691- )
692- . file ( "src/lib.rs" , "" )
693- . build ( ) ;
694-
695- p. cargo ( "check" )
696- . arg ( "-Zgitoxide=fetch" )
697- . arg ( "-Zgit=shallow-deps" )
698- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
699- . run ( ) ;
700-
701- assert ! (
702- db_clone. is_shallow( ) ,
703- "we maintain shallowness and never unshallow"
704- ) ;
705-
706- Ok ( ( ) )
707- }
708-
709- #[ cargo_test]
710- fn shallow_deps_work_with_revisions_and_branches_mixed_on_same_dependency ( ) -> anyhow:: Result < ( ) > {
711- let ( bar, bar_repo) = git:: new_repo ( "bar" , |p| {
712- p. file ( "Cargo.toml" , & basic_manifest ( "bar" , "1.0.0" ) )
713- . file ( "src/lib.rs" , "" )
714- } ) ;
715-
716- // this commit would not be available in a shallow fetch.
717- let first_commit_pre_change = bar_repo. head ( ) . unwrap ( ) . target ( ) . unwrap ( ) ;
718-
719- bar. change_file ( "src/lib.rs" , "// change" ) ;
720- git:: add ( & bar_repo) ;
721- git:: commit ( & bar_repo) ;
722-
723- let p = project ( )
724- . file (
725- "Cargo.toml" ,
726- & format ! (
727- r#"
728- [package]
729- name = "foo"
730- version = "0.1.0"
731-
732- [dependencies]
733- bar-renamed = {{ package = "bar", git = "{}", rev = "{}" }}
734- bar = {{ git = "{}", branch = "master" }}
735- "# ,
736- bar. url( ) ,
737- first_commit_pre_change,
738- bar. url( ) ,
739- ) ,
740- )
741- . file ( "src/lib.rs" , "" )
742- . build ( ) ;
743-
744- p. cargo ( "check" )
745- . arg ( "-Zgitoxide=fetch" )
746- . arg ( "-Zgit=shallow-deps" )
747- . masquerade_as_nightly_cargo ( & [ "gitoxide=fetch" , "git=shallow-deps" ] )
748- . run ( ) ;
749-
750- let db_paths = glob:: glob ( paths:: home ( ) . join ( ".cargo/git/db/bar-*" ) . to_str ( ) . unwrap ( ) ) ?
751- . map ( Result :: unwrap)
752- . collect :: < Vec < _ > > ( ) ;
753- assert_eq ! (
754- db_paths. len( ) ,
755- 1 ,
756- "only one db checkout source is used per dependency"
757- ) ;
758- let db_clone = gix:: open_opts ( & db_paths[ 0 ] , gix:: open:: Options :: isolated ( ) ) ?;
759- assert ! (
760- db_clone. is_shallow( ) ,
761- "the repo is shallow while having all data it needs"
762- ) ;
763-
764- Ok ( ( ) )
765- }
766-
767767#[ cargo_test]
768768fn gitoxide_fetch_registry_with_shallow_protocol_and_aborts_and_updates_again ( ) -> anyhow:: Result < ( ) >
769769{
0 commit comments