@@ -110,7 +110,7 @@ use std::fs::{self, File};
110
110
use std:: io;
111
111
use std:: io:: ErrorKind ;
112
112
use std:: path:: { Path , PathBuf } ;
113
- use std:: process:: Command ;
113
+ use std:: process:: { Command , Stdio } ;
114
114
use std:: str;
115
115
116
116
use build_helper:: ci:: CiEnv ;
@@ -662,12 +662,32 @@ impl Build {
662
662
663
663
// Try passing `--progress` to start, then run git again without if that fails.
664
664
let update = |progress : bool | {
665
- let mut git = Command :: new ( "git" ) ;
665
+ // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
666
+ // even though that has no relation to the upstream for the submodule.
667
+ let current_branch = {
668
+ let output = self
669
+ . config
670
+ . git ( )
671
+ . args ( [ "symbolic-ref" , "--short" , "HEAD" ] )
672
+ . stderr ( Stdio :: inherit ( ) )
673
+ . output ( ) ;
674
+ let output = t ! ( output) ;
675
+ if output. status . success ( ) {
676
+ Some ( String :: from_utf8 ( output. stdout ) . unwrap ( ) . trim ( ) . to_owned ( ) )
677
+ } else {
678
+ None
679
+ }
680
+ } ;
681
+
682
+ let mut git = self . config . git ( ) ;
683
+ if let Some ( branch) = current_branch {
684
+ git. arg ( "-c" ) . arg ( format ! ( "branch.{branch}.remote=origin" ) ) ;
685
+ }
666
686
git. args ( & [ "submodule" , "update" , "--init" , "--recursive" , "--depth=1" ] ) ;
667
687
if progress {
668
688
git. arg ( "--progress" ) ;
669
689
}
670
- git. arg ( relative_path) . current_dir ( & self . config . src ) ;
690
+ git. arg ( relative_path) ;
671
691
git
672
692
} ;
673
693
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.
0 commit comments