Skip to content

Commit f7a9ee2

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 af35d48 commit f7a9ee2

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
@@ -109,7 +109,7 @@ use std::env;
109109
use std::fs::{self, File};
110110
use std::io;
111111
use std::path::{Path, PathBuf};
112-
use std::process::Command;
112+
use std::process::{Command, Stdio};
113113
use std::str;
114114

115115
use channel::GitInfo;
@@ -643,12 +643,32 @@ impl Build {
643643

644644
// Try passing `--progress` to start, then run git again without if that fails.
645645
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+
}
647667
git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]);
648668
if progress {
649669
git.arg("--progress");
650670
}
651-
git.arg(relative_path).current_dir(&self.config.src);
671+
git.arg(relative_path);
652672
git
653673
};
654674
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.

0 commit comments

Comments
 (0)