From 030bb57924c0ee1db601b5bcdbba04364673a001 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 30 Mar 2020 17:31:37 -0700 Subject: [PATCH] Show commit hash in version when built from source Users might file an issue while running an older version, but the issue has already been fixed in master. Adding the git revision to the version output will expedite this diagnosis. For example: $ zoxide -V zoxide 0.3.0-0191eea --- build.rs | 14 ++++++++++++++ src/main.rs | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f167873 --- /dev/null +++ b/build.rs @@ -0,0 +1,14 @@ +fn main() { + let mut hash = std::process::Command::new("git") + .args(&["rev-parse", "--short", "HEAD"]) + .output() + .ok() + .and_then(|proc| String::from_utf8(proc.stdout).ok()) + .unwrap_or_default(); + + if !hash.is_empty() { + hash = format!("-{}", hash); + } + + println!("cargo:rustc-env=GIT_HASH={}", hash); +} diff --git a/src/main.rs b/src/main.rs index a480b45..63e617e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,10 @@ use anyhow::Result; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "A cd command that learns your habits")] +#[structopt( + about = "A cd command that learns your habits", + version = concat!(env!("CARGO_PKG_VERSION"), env!("GIT_HASH")) +)] enum Zoxide { Add(subcommand::Add), Import(subcommand::Import),