Skip to content

Commit ed7db22

Browse files
Merge pull request #861 from adamgemmell/bugfix/rust-ref-checkout
Use default branch for rustc if the chosen ref doesn't exist
2 parents 6be295e + f4971e9 commit ed7db22

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

collector/src/execute/rustc.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn record(
3737
aid: database::ArtifactIdNumber,
3838
) -> anyhow::Result<()> {
3939
let checkout = Path::new("rust");
40-
let status = Command::new("git")
40+
let mut status = Command::new("git")
4141
.current_dir("rust")
4242
.arg("reset")
4343
.arg("--hard")
@@ -47,7 +47,19 @@ fn record(
4747
})
4848
.status()
4949
.context("git reset --hard")?;
50+
51+
if !status.success() && matches!(artifact, ArtifactId::Artifact(_)) {
52+
log::warn!("git reset --hard {} failed - trying default branch", artifact);
53+
status = Command::new("git")
54+
.current_dir("rust")
55+
.arg("reset")
56+
.arg("--hard")
57+
.arg("origin/HEAD")
58+
.status()
59+
.context("git reset --hard")?;
60+
}
5061
assert!(status.success(), "git reset --hard successful");
62+
5163
let status = Command::new("git")
5264
.current_dir("rust")
5365
.arg("clean")
@@ -144,7 +156,7 @@ fn record(
144156

145157
fn checkout(artifact: &ArtifactId) -> anyhow::Result<()> {
146158
if Path::new("rust").exists() {
147-
let status = Command::new("git")
159+
let mut status = Command::new("git")
148160
.current_dir("rust")
149161
.arg("fetch")
150162
.arg("origin")
@@ -154,7 +166,19 @@ fn checkout(artifact: &ArtifactId) -> anyhow::Result<()> {
154166
})
155167
.status()
156168
.context("git fetch origin")?;
169+
170+
if !status.success() && matches!(artifact, ArtifactId::Artifact(_)) {
171+
log::warn!("git fetch origin {} failed - trying default branch", artifact);
172+
status = Command::new("git")
173+
.current_dir("rust")
174+
.arg("fetch")
175+
.arg("origin")
176+
.arg("HEAD")
177+
.status()
178+
.context("git fetch origin HEAD")?;
179+
}
157180
assert!(status.success(), "git fetch successful");
181+
158182
} else {
159183
let status = Command::new("git")
160184
.arg("clone")

0 commit comments

Comments
 (0)