about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-04 00:27:32 +0000
committerbors <bors@rust-lang.org>2022-12-04 00:27:32 +0000
commit2a39e45afba72fb2d456a02af4d290d16aebe621 (patch)
tree75b531a9c9c20f2bb3e4f20054338be0ca68a6b6
parentb8a52e3a4ba9549edb71836561be13e73a8a50a7 (diff)
parenta0e56154f31163a0b9dc5c13874d020988240fc6 (diff)
downloadrust-2a39e45afba72fb2d456a02af4d290d16aebe621.tar.gz
rust-2a39e45afba72fb2d456a02af4d290d16aebe621.zip
Auto merge of #105217 - jyn514:submodule-fixes, r=bjorn3
Don't exit with an error if there are no changes to submodules

Fixes https://github.com/rust-lang/rust/issues/105215, which regressed in https://github.com/rust-lang/rust/pull/104865.
-rw-r--r--src/bootstrap/lib.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index a3d1893afbb..d69bced0b28 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -647,10 +647,23 @@ impl Build {
         if !update(true).status().map_or(false, |status| status.success()) {
             self.run(&mut update(false));
         }
-        self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path));
+
+        // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
+        let has_local_modifications = !self.try_run(
+            Command::new("git")
+                .args(&["diff-index", "--quiet", "HEAD"])
+                .current_dir(&absolute_path),
+        );
+        if has_local_modifications {
+            self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path));
+        }
+
         self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path));
         self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(&absolute_path));
-        self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path));
+
+        if has_local_modifications {
+            self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path));
+        }
     }
 
     /// If any submodule has been initialized already, sync it unconditionally.