@@ -109,7 +109,7 @@ use std::env;
109
109
use std:: fs:: { self , File } ;
110
110
use std:: io;
111
111
use std:: path:: { Path , PathBuf } ;
112
- use std:: process:: Command ;
112
+ use std:: process:: { Command , Stdio } ;
113
113
use std:: str;
114
114
115
115
use channel:: GitInfo ;
@@ -643,12 +643,32 @@ impl Build {
643
643
644
644
// Try passing `--progress` to start, then run git again without if that fails.
645
645
let update = |progress : bool | {
646
- let mut git = Command :: new ( "git" ) ;
646
+ // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
647
+ // even though that has no relation to the upstream for the submodule.
648
+ let current_branch = {
649
+ let output = self
650
+ . config
651
+ . git ( )
652
+ . args ( [ "symbolic-ref" , "--short" , "HEAD" ] )
653
+ . stderr ( Stdio :: inherit ( ) )
654
+ . output ( ) ;
655
+ let output = t ! ( output) ;
656
+ if output. status . success ( ) {
657
+ Some ( String :: from_utf8 ( output. stdout ) . unwrap ( ) . trim ( ) . to_owned ( ) )
658
+ } else {
659
+ None
660
+ }
661
+ } ;
662
+
663
+ let mut git = self . config . git ( ) ;
664
+ if let Some ( branch) = current_branch {
665
+ git. arg ( "-c" ) . arg ( format ! ( "branch.{branch}.remote=origin" ) ) ;
666
+ }
647
667
git. args ( & [ "submodule" , "update" , "--init" , "--recursive" , "--depth=1" ] ) ;
648
668
if progress {
649
669
git. arg ( "--progress" ) ;
650
670
}
651
- git. arg ( relative_path) . current_dir ( & self . config . src ) ;
671
+ git. arg ( relative_path) ;
652
672
git
653
673
} ;
654
674
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.
0 commit comments