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