diff --git a/internal/config/exec.go b/internal/config/exec.go index 54a8f6e9..87971979 100644 --- a/internal/config/exec.go +++ b/internal/config/exec.go @@ -24,7 +24,7 @@ func (o *osExec) Cmd(commandLine string) bool { var cmd *exec.Cmd if runtime.GOOS == "windows" { - cmd = exec.Command("cmd", "/C", commandLine) + cmd = exec.Command("powershell", "-Command", commandLine) } else { cmd = exec.Command("sh", "-c", commandLine) } diff --git a/testdata/skip_run.txt b/testdata/skip_run.txt index 0db312bb..7e2af672 100644 --- a/testdata/skip_run.txt +++ b/testdata/skip_run.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec git add -A exec lefthook run skip @@ -5,14 +7,12 @@ exec lefthook run skip exec lefthook run no-skip stdout 'Ha-ha!' -[unix] exec lefthook run skip-var -[windows] exec lefthook run skip-var-windows +exec lefthook run skip-var ! stdout 'Ha-ha!' env VAR=1 -[unix] exec lefthook run skip-var -[windows] exec lefthook run skip-var-windows - stdout 'Ha-ha!' +exec lefthook run skip-var +stdout 'Ha-ha!' -- lefthook.yml -- skip_output: @@ -40,10 +40,3 @@ skip-var: commands: echo: run: echo 'Ha-ha!' - -skip-var-windows: - skip: - - run: if (-not $env:VAR) { exit 1 } else { exit 0 } - commands: - echo: - run: echo 'Ha-ha!' diff --git a/testdata/skip_run_windows.txt b/testdata/skip_run_windows.txt new file mode 100644 index 00000000..336e3b55 --- /dev/null +++ b/testdata/skip_run_windows.txt @@ -0,0 +1,42 @@ +[!windows] skip + +exec git init +exec git add -A +exec lefthook run skip +! stdout 'Ha-ha!' +exec lefthook run no-skip +stdout 'Ha-ha!' + +exec lefthook run skip-var-windows +! stdout 'Ha-ha!' + +env VAR=1 +exec lefthook run skip-var-windows +stdout 'Ha-ha!' + +-- lefthook.yml -- +skip_output: + - skips + - meta + - summary + - execution_info +skip: + skip: + - run: if (1 -eq 1) { exit 0 } else { exit 1 } + commands: + echo: + run: echo 'Ha-ha!' + +no-skip: + skip: + - run: if (1 -eq 0) { exit 0 } else { exit 1 } + commands: + echo: + run: echo 'Ha-ha!' + +skip-var: + skip: + - run: if ([string]::IsNullOrEmpty($env:VAR)) { exit 1 } else { exit 0 } + commands: + echo: + run: echo 'Ha-ha!'