fixup! squash! fixup! Show commit hash in version when built from source
This commit is contained in:
parent
f4d237d07a
commit
f9f144e1ef
38
build.rs
38
build.rs
|
|
@ -1,35 +1,17 @@
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let status_code = Command::new("git")
|
let git_describe = std::process::Command::new("git")
|
||||||
.args(&["describe", "--tags", "--exact-match", "--dirty"])
|
.args(&["describe", "--tags", "--broken"])
|
||||||
.status()
|
|
||||||
.ok()
|
|
||||||
.and_then(|status| status.code());
|
|
||||||
|
|
||||||
let is_tagged = match status_code {
|
|
||||||
Some(code) => code == 0,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// If this is a tagged commit (a release), we don't want to include the
|
|
||||||
// commit hash in the version output.
|
|
||||||
let revision = if is_tagged {
|
|
||||||
String::new()
|
|
||||||
} else {
|
|
||||||
let mut hash = Command::new("git")
|
|
||||||
.args(&["rev-parse", "--short", "HEAD"])
|
|
||||||
.output()
|
.output()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|proc| String::from_utf8(proc.stdout).ok())
|
.and_then(|proc| String::from_utf8(proc.stdout).ok());
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if !hash.is_empty() {
|
let mut version_info = format!("v{}-unknown", env!("CARGO_PKG_VERSION"));
|
||||||
hash = format!("-{}", hash);
|
|
||||||
|
if let Some(description) = git_describe {
|
||||||
|
if !description.is_empty() {
|
||||||
|
version_info = description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hash
|
println!("cargo:rustc-env=ZOXIDE_VERSION={}", version_info);
|
||||||
};
|
|
||||||
|
|
||||||
println!("cargo:rustc-env=GIT_HASH={}", revision);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,7 @@ use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(
|
#[structopt(about = "A cd command that learns your habits", version = env!("ZOXIDE_VERSION"))]
|
||||||
about = "A cd command that learns your habits",
|
|
||||||
version = concat!(env!("CARGO_PKG_VERSION"), env!("GIT_HASH"))
|
|
||||||
)]
|
|
||||||
enum Zoxide {
|
enum Zoxide {
|
||||||
Add(subcommand::Add),
|
Add(subcommand::Add),
|
||||||
Import(subcommand::Import),
|
Import(subcommand::Import),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue