Skip to content

Commit 6a3ebe6

Browse files
committed
Pass branch.{branch}.remote=origin to git submodule update
This works around a bug in git itself; see rust-lang#101144.
1 parent af3e06f commit 6a3ebe6

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/bootstrap/lib.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use std::fs::{self, File};
110110
use std::io;
111111
use std::io::ErrorKind;
112112
use std::path::{Path, PathBuf};
113-
use std::process::Command;
113+
use std::process::{Command, Stdio};
114114
use std::str;
115115

116116
use channel::GitInfo;
@@ -661,12 +661,32 @@ impl Build {
661661

662662
// Try passing `--progress` to start, then run git again without if that fails.
663663
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+
}
665685
git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]);
666686
if progress {
667687
git.arg("--progress");
668688
}
669-
git.arg(relative_path).current_dir(&self.config.src);
689+
git.arg(relative_path);
670690
git
671691
};
672692
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.

0 commit comments

Comments
 (0)