From 2e1ffa313fefb4e14e2e59388dc4bbfbdebcdb34 Mon Sep 17 00:00:00 2001 From: Jo <10510431+j178@users.noreply.github.com> Date: Wed, 14 Jan 2026 16:02:07 +0800 Subject: [PATCH] Fix missing commit hash from version info (#1352) --- crates/prek/build.rs | 7 ++++++- crates/prek/tests/run.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/prek/build.rs b/crates/prek/build.rs index e73efa16..77145095 100644 --- a/crates/prek/build.rs +++ b/crates/prek/build.rs @@ -30,7 +30,12 @@ fn main() { // The workspace root directory is not available without walking up the tree // https://github.com/rust-lang/cargo/issues/3946 #[allow(clippy::disallowed_methods)] - let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).to_path_buf(); + let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) + .parent() + .expect("CARGO_MANIFEST_DIR should be nested in workspace") + .parent() + .expect("CARGO_MANIFEST_DIR should be doubly nested in workspace") + .to_path_buf(); commit_info(&workspace_root); } diff --git a/crates/prek/tests/run.rs b/crates/prek/tests/run.rs index 9b54e7b6..96dace7c 100644 --- a/crates/prek/tests/run.rs +++ b/crates/prek/tests/run.rs @@ -2785,3 +2785,25 @@ fn run_with_stdin_closed() { ----- stderr ----- "); } + +/// Test `prek --version` outputs version info. +#[test] +fn version_info() { + let context = TestContext::new(); + let filters = context + .filters() + .into_iter() + .chain([( + r"prek \d+\.\d+\.\d+(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?(\+\d+)? \(\w{9} [\d\-T:\.]+\)", + "prek [CURRENT_VERSION] ([COMMIT] [DATE])", + )]) + .collect::>(); + cmd_snapshot!(filters, context.command().arg("--version"), @r" + success: true + exit_code: 0 + ----- stdout ----- + prek [CURRENT_VERSION] ([COMMIT] [DATE]) + + ----- stderr ----- + "); +}