Skip to content

Commit

Permalink
work with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Mar 12, 2024
1 parent 9a36234 commit d9ee67e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/config/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 5 additions & 12 deletions testdata/skip_run.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[windows] skip

exec git init
exec git add -A
exec lefthook run skip
! stdout 'Ha-ha!'
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:
Expand Down Expand Up @@ -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!'
42 changes: 42 additions & 0 deletions testdata/skip_run_windows.txt
Original file line number Diff line number Diff line change
@@ -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!'

0 comments on commit d9ee67e

Please sign in to comment.