Merge pull request #815 from sbellem/git-describe-abbrev

Fix git describe abbrev length for reproducibility
This commit is contained in:
bunnie 2026-02-12 19:42:26 +08:00 committed by GitHub
commit 3f9381f3db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,20 +8,25 @@ use std::process::Command;
use chrono::{Local, TimeZone, Utc};
/// Fixed abbreviation length for `git describe` output.
/// Ensures consistent version strings regardless of clone depth.
const GIT_ABBREV_LEN: u8 = 9;
pub(crate) fn generate_version(add_timestamp: bool, forced_version: Option<String>) {
let gitver = {
if let Some(ver) = forced_version {
ver.as_bytes().to_vec()
} else {
let cmd = format!("git describe --long --abbrev={}", GIT_ABBREV_LEN);
let output = if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", "git describe --long"])
.args(["/C", &cmd])
.output()
.expect("failed to execute process")
} else {
Command::new("sh")
.arg("-c")
.arg("git describe --long")
.arg(&cmd)
.output()
.expect("failed to execute process")
};