about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorJoshua Nelson <github@jyn.dev>2022-12-23 20:02:34 -0600
committerJoshua Nelson <github@jyn.dev>2022-12-23 20:10:22 -0600
commit6a3ebe6adc58b60cf963b2dd314bc84afd59a0a2 (patch)
treeb99b8309768be8cba6d2fa9e7d30214e3be32301 /src/bootstrap
parentaf3e06f1bf4ca49407562b1b84744e27905bea98 (diff)
downloadrust-6a3ebe6adc58b60cf963b2dd314bc84afd59a0a2.tar.gz
rust-6a3ebe6adc58b60cf963b2dd314bc84afd59a0a2.zip
Pass `branch.{branch}.remote=origin` to `git submodule update`
This works around a bug in git itself; see
https://github.com/rust-lang/rust/issues/101144.
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/lib.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index f84fcd21cfc..5cdd841cd6e 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -110,7 +110,7 @@ use std::fs::{self, File};
 use std::io;
 use std::io::ErrorKind;
 use std::path::{Path, PathBuf};
-use std::process::Command;
+use std::process::{Command, Stdio};
 use std::str;
 
 use channel::GitInfo;
@@ -661,12 +661,32 @@ impl Build {
 
         // Try passing `--progress` to start, then run git again without if that fails.
         let update = |progress: bool| {
-            let mut git = Command::new("git");
+            // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
+            // even though that has no relation to the upstream for the submodule.
+            let current_branch = {
+                let output = self
+                    .config
+                    .git()
+                    .args(["symbolic-ref", "--short", "HEAD"])
+                    .stderr(Stdio::inherit())
+                    .output();
+                let output = t!(output);
+                if output.status.success() {
+                    Some(String::from_utf8(output.stdout).unwrap().trim().to_owned())
+                } else {
+                    None
+                }
+            };
+
+            let mut git = self.config.git();
+            if let Some(branch) = current_branch {
+                git.arg("-c").arg(format!("branch.{branch}.remote=origin"));
+            }
             git.args(&["submodule", "update", "--init", "--recursive", "--depth=1"]);
             if progress {
                 git.arg("--progress");
             }
-            git.arg(relative_path).current_dir(&self.config.src);
+            git.arg(relative_path);
             git
         };
         // NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.