Skip to content

Commit 2a39e45

Browse files
committed
Auto merge of rust-lang#105217 - jyn514:submodule-fixes, r=bjorn3
Don't exit with an error if there are no changes to submodules Fixes rust-lang#105215, which regressed in rust-lang#104865.
2 parents b8a52e3 + a0e5615 commit 2a39e45

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/bootstrap/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,23 @@ impl Build {
647647
if !update(true).status().map_or(false, |status| status.success()) {
648648
self.run(&mut update(false));
649649
}
650-
self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path));
650+
651+
// Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
652+
let has_local_modifications = !self.try_run(
653+
Command::new("git")
654+
.args(&["diff-index", "--quiet", "HEAD"])
655+
.current_dir(&absolute_path),
656+
);
657+
if has_local_modifications {
658+
self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path));
659+
}
660+
651661
self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path));
652662
self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(&absolute_path));
653-
self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path));
663+
664+
if has_local_modifications {
665+
self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path));
666+
}
654667
}
655668

656669
/// If any submodule has been initialized already, sync it unconditionally.

0 commit comments

Comments
 (0)