@@ -230,15 +230,23 @@ impl GitRemote {
230230 locked_rev : Option < GitOid > ,
231231 client : & ClientWithMiddleware ,
232232 disable_ssl : bool ,
233+ offline : bool ,
233234 ) -> Result < ( GitDatabase , GitOid ) > {
234235 let reference = locked_rev
235236 . map ( ReferenceOrOid :: Oid )
236237 . unwrap_or ( ReferenceOrOid :: Reference ( reference) ) ;
237238 let enable_lfs_fetch = env:: var ( EnvVars :: UV_GIT_LFS ) . is_ok ( ) ;
238239
239240 if let Some ( mut db) = db {
240- fetch ( & mut db. repo , & self . url , reference, client, disable_ssl)
241- . with_context ( || format ! ( "failed to fetch into: {}" , into. user_display( ) ) ) ?;
241+ fetch (
242+ & mut db. repo ,
243+ & self . url ,
244+ reference,
245+ client,
246+ disable_ssl,
247+ offline,
248+ )
249+ . with_context ( || format ! ( "failed to fetch into: {}" , into. user_display( ) ) ) ?;
242250
243251 let resolved_commit_hash = match locked_rev {
244252 Some ( rev) => db. contains ( rev) . then_some ( rev) ,
@@ -265,8 +273,15 @@ impl GitRemote {
265273
266274 fs_err:: create_dir_all ( into) ?;
267275 let mut repo = GitRepository :: init ( into) ?;
268- fetch ( & mut repo, & self . url , reference, client, disable_ssl)
269- . with_context ( || format ! ( "failed to clone into: {}" , into. user_display( ) ) ) ?;
276+ fetch (
277+ & mut repo,
278+ & self . url ,
279+ reference,
280+ client,
281+ disable_ssl,
282+ offline,
283+ )
284+ . with_context ( || format ! ( "failed to clone into: {}" , into. user_display( ) ) ) ?;
270285 let rev = match locked_rev {
271286 Some ( rev) => rev,
272287 None => reference. resolve ( & repo) ?,
@@ -441,6 +456,7 @@ fn fetch(
441456 reference : ReferenceOrOid < ' _ > ,
442457 client : & ClientWithMiddleware ,
443458 disable_ssl : bool ,
459+ offline : bool ,
444460) -> Result < ( ) > {
445461 let oid_to_fetch = match github_fast_path ( repo, remote_url, reference, client) {
446462 Ok ( FastPathRev :: UpToDate ) => return Ok ( ( ) ) ,
@@ -516,9 +532,14 @@ fn fetch(
516532
517533 debug ! ( "Performing a Git fetch for: {remote_url}" ) ;
518534 let result = match refspec_strategy {
519- RefspecStrategy :: All => {
520- fetch_with_cli ( repo, remote_url, refspecs. as_slice ( ) , tags, disable_ssl)
521- }
535+ RefspecStrategy :: All => fetch_with_cli (
536+ repo,
537+ remote_url,
538+ refspecs. as_slice ( ) ,
539+ tags,
540+ disable_ssl,
541+ offline,
542+ ) ,
522543 RefspecStrategy :: First => {
523544 // Try each refspec
524545 let mut errors = refspecs
@@ -530,6 +551,7 @@ fn fetch(
530551 std:: slice:: from_ref ( refspec) ,
531552 tags,
532553 disable_ssl,
554+ offline,
533555 ) ;
534556
535557 // Stop after the first success and log failures
@@ -576,6 +598,7 @@ fn fetch_with_cli(
576598 refspecs : & [ String ] ,
577599 tags : bool ,
578600 disable_ssl : bool ,
601+ offline : bool ,
579602) -> Result < ( ) > {
580603 let mut cmd = ProcessBuilder :: new ( GIT . as_ref ( ) ?) ;
581604 // Disable interactive prompts in the terminal, as they'll be erased by the progress bar
@@ -591,6 +614,10 @@ fn fetch_with_cli(
591614 debug ! ( "Disabling SSL verification for Git fetch" ) ;
592615 cmd. env ( EnvVars :: GIT_SSL_NO_VERIFY , "true" ) ;
593616 }
617+ if offline {
618+ debug ! ( "Offline - setting GIT_ALLOW_PROTOCOL=file" ) ;
619+ cmd. env ( EnvVars :: GIT_ALLOW_PROTOCOL , "file" ) ;
620+ }
594621 cmd. arg ( "--force" ) // handle force pushes
595622 . arg ( "--update-head-ok" ) // see discussion in #2078
596623 . arg ( url. as_str ( ) )
0 commit comments