on master help sign in
fix: Only parse git revision, don't use the tag for version

If building from source and the source is contained in a larger repository, we'd contain the wrong version. It's also easy to accidentally have a newer tag that would change the version.

commitd3221b03a2b3ee5acc68066f34c4e56e2d05ce94 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 3 Feb 2022, 01:19 (5 years ago) parentd6b6ad8
1 file changed+10−5
helix-term/build.rs+10−5
helix-term/build.rs+10−5
@@ -1,12 +1,17 @@
1+use std::borrow::Cow;
12use std::process::Command;
23
34fn main() {
45 let git_hash = Command::new("git")
5− .args(&["describe", "--dirty"])
6+ .args(&["rev-parse", "HEAD"])
67 .output()
7− .map(|x| String::from_utf8(x.stdout).ok())
88 .ok()
9− .flatten()
10− .unwrap_or_else(|| String::from(env!("CARGO_PKG_VERSION")));
11− println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", git_hash);
9+ .and_then(|x| String::from_utf8(x.stdout).ok());
10+
11+ let version: Cow<_> = match git_hash {
12+ Some(git_hash) => format!("{} ({})", env!("CARGO_PKG_VERSION"), &git_hash[..8]).into(),
13+ None => env!("CARGO_PKG_VERSION").into(),
14+ };
15+
16+ println!("cargo:rustc-env=VERSION_AND_GIT_HASH={}", version);
1217}