Skip to content

Commit 8f28be6

Browse files
committed
Fix CLI build script
1 parent 4c829c1 commit 8f28be6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

quickwit-cli/build.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919

2020
use std::process::Command;
2121

22+
const UNKNOWN: &str = "unknown";
23+
2224
fn main() {
23-
let git_commit_hash = Command::new("git")
24-
.args(&["rev-parse", "HEAD"])
25-
.output()
26-
.map_or("unknown".to_string(), |output| {
27-
let hash = String::from_utf8(output.stdout).unwrap();
28-
String::from(&hash[..7])
29-
});
30-
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash);
25+
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_rev_parse_head());
26+
}
27+
28+
fn git_rev_parse_head() -> String {
29+
let mut stdout = match Command::new("git").args(&["rev-parse", "HEAD"]).output() {
30+
Ok(output) if output.status.success() => output.stdout,
31+
_ => return UNKNOWN.to_string(),
32+
};
33+
stdout.truncate(7);
34+
String::from_utf8(stdout).unwrap_or_else(|_| UNKNOWN.to_string())
3135
}

0 commit comments

Comments
 (0)