Skip to content

Commit a77c85d

Browse files
authored
fix: set default hash in case git is not available
Signed-off-by: Mats Willemsen <60099717+ma-ts@users.noreply.github.com>
1 parent 90b4ec6 commit a77c85d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ fn main() -> Result<()> {
1818
// Supply information as compile-time environment variables.
1919
#[cfg(feature = "opa-runtime")]
2020
{
21-
let output = std::process::Command::new("git")
21+
let git_hash = std::process::Command::new("git")
2222
.args(["rev-parse", "HEAD"])
2323
.output()
24-
.expect("`git rev-parse HEAD` failed.");
25-
let git_hash = String::from_utf8(output.stdout).unwrap();
26-
println!("cargo:rustc-env=GIT_HASH={git_hash}");
24+
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string())
25+
.unwrap_or_else(|_| "unknown".to_string());
26+
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
2727
}
2828

2929
// Rerun only if build.rs changes.

0 commit comments

Comments
 (0)