Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6cdc68f

Browse files
authoredJan 29, 2023
Rollup merge of rust-lang#106106 - jyn514:remote-tracking-branch, r=Mark-Simulacrum
Pass `branch.{branch}.remote=origin` to `git submodule update` This works around a bug in git itself. Fixes rust-lang#101144.
2 parents e972bc8 + 6a3ebe6 commit 6cdc68f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed
 

Diff for: ‎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 build_helper::ci::CiEnv;
@@ -662,12 +662,32 @@ impl Build {
662662

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

0 commit comments

Comments
 (0)
Please sign in to comment.