diff options
| author | David Tolnay <dtolnay@gmail.com> | 2024-08-04 10:42:08 -0700 |
|---|---|---|
| committer | Yacin Tmimi <yacintmimi@gmail.com> | 2024-08-04 12:44:32 -0600 |
| commit | 15c75fec4fcf3cb0ab63c34bf1b11e2e7577c5c2 (patch) | |
| tree | b91f4e1c6b77f36e74ce3be4b28743c8738f627f | |
| parent | 17c5869dffc21356559f223770cbfa0648692808 (diff) | |
| download | rust-15c75fec4fcf3cb0ab63c34bf1b11e2e7577c5c2.tar.gz rust-15c75fec4fcf3cb0ab63c34bf1b11e2e7577c5c2.zip | |
Check exit status of git commands spawned by build script
| -rw-r--r-- | build.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/build.rs b/build.rs index 8e1ed287159..696c713d726 100644 --- a/build.rs +++ b/build.rs @@ -43,15 +43,16 @@ fn commit_hash() -> Option<String> { .args(["rev-parse", "HEAD"]) .output() .ok()?; - let mut stdout = String::from_utf8(output.stdout).ok()?; + let mut stdout = output.status.success().then_some(output.stdout)?; stdout.truncate(10); - Some(stdout) + String::from_utf8(stdout).ok() } fn commit_date() -> Option<String> { - Command::new("git") + let output = Command::new("git") .args(["log", "-1", "--date=short", "--pretty=format:%cd"]) .output() - .ok() - .and_then(|r| String::from_utf8(r.stdout).ok()) + .ok()?; + let stdout = output.status.success().then_some(output.stdout)?; + String::from_utf8(stdout).ok() } |
