1
0
mirror of https://github.com/j178/prek.git synced 2026-04-03 17:34:03 +02:00

Fix command lookup on Windows (#1383)

* Add a failing test

* Fix

* Docker entry should not be resolved
This commit is contained in:
Jo
2026-01-17 22:53:13 +08:00
committed by GitHub
parent 414d0cc088
commit 85448ac471
3 changed files with 47 additions and 1 deletions

View File

@@ -481,7 +481,7 @@ impl LanguageImpl for Docker {
)
.await
.context("Failed to build docker image")?;
let entry = hook.entry.resolve(None)?;
let entry = hook.entry.split()?;
let run = async |batch: &[&Path]| {
// docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

View File

@@ -272,6 +272,13 @@ pub(crate) async fn extract_metadata_from_entry(hook: &mut Hook) -> Result<()> {
/// Resolve the actual process invocation, honoring shebangs and PATH lookups.
pub(crate) fn resolve_command(mut cmds: Vec<String>, paths: Option<&OsStr>) -> Vec<String> {
let env_path = if paths.is_none() {
EnvVars::var_os(EnvVars::PATH)
} else {
None
};
let paths = paths.or(env_path.as_deref());
let candidate = &cmds[0];
let resolved_binary = match which::which_in(candidate, paths, &*CWD) {
Ok(p) => p,

View File

@@ -241,3 +241,42 @@ fn doctoc() -> anyhow::Result<()> {
Ok(())
}
/// Test that `npm.cmd` can be found on Windows.
#[test]
fn npm_version() {
let context = TestContext::new();
context.init_project();
context.write_pre_commit_config(indoc::indoc! {r"
repos:
- repo: local
hooks:
- id: npm-version
name: npm-version
language: system
entry: npm --version
always_run: true
pass_filenames: false
verbose: true
"});
context.git_add(".");
let filters = context
.filters()
.into_iter()
.chain([(r"\d+\.\d+\.\d+", "[NPM_VERSION]")])
.collect::<Vec<_>>();
cmd_snapshot!(filters, context.run(), @r"
success: true
exit_code: 0
----- stdout -----
npm-version..............................................................Passed
- hook id: npm-version
- duration: [TIME]
[NPM_VERSION]
----- stderr -----
");
}