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 348e67c
Show file tree
Hide file tree
Showing 10 changed files with 63 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
2 changes: 2 additions & 0 deletions testdata/add.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

exec git init
exec lefthook add pre-commit
! stderr .
Expand Down
2 changes: 2 additions & 0 deletions testdata/dump.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

exec git init
exec lefthook dump
cmp stdout lefthook-dumped.yml
Expand Down
2 changes: 2 additions & 0 deletions testdata/hide_unstaged.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

exec git init
exec lefthook install
exec git config user.email "[email protected]"
Expand Down
2 changes: 2 additions & 0 deletions testdata/remote.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

exec git init
exec lefthook install

Expand Down
2 changes: 2 additions & 0 deletions testdata/remotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

exec git init
exec lefthook install

Expand Down
2 changes: 2 additions & 0 deletions testdata/run_interrupt.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[windows] skip

chmod 0700 hook.sh
chmod 0700 commit-with-interrupt.sh
exec git init
Expand Down
3 changes: 3 additions & 0 deletions testdata/sh_syntax_in_files.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[windows] skip

exec git init
exec lefthook install
exec git config user.email "[email protected]"
exec git config user.name "Your Name"

exec lefthook run echo_files

stdout '1.txt 10.txt'

-- lefthook.yml --
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
! stdout 'Ha-ha!'

env VAR=1
exec lefthook run skip-var
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 0 } else { exit 1 }
commands:
echo:
run: echo 'Ha-ha!'

0 comments on commit 348e67c

Please sign in to comment.