From f4d8b2554a2b750fc2bb0781840ef8c726a0f9a2 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Mon, 19 Feb 2024 14:21:21 +0100 Subject: [PATCH 1/9] handle "run" command in the skip/only setting --- docs/configuration.md | 15 +++++++ internal/config/command.go | 3 +- internal/config/exec.go | 34 +++++++++++++++ internal/config/hook.go | 3 +- internal/config/script.go | 3 +- internal/config/skip.go | 83 +++++++++++++++++++++++++++--------- internal/config/skip_test.go | 28 +++++++++++- 7 files changed, 145 insertions(+), 24 deletions(-) create mode 100644 internal/config/exec.go diff --git a/docs/configuration.md b/docs/configuration.md index 5c8bb04e..ff646b89 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -884,6 +884,21 @@ pre-commit: run: yarn test ``` +Skipping hook by running a command: + +```yml +# lefthook.yml + +pre-commit: + skip: + - run: test "${NO_HOOK}" -eq 1 + commands: + lint: + run: yarn lint + text: + run: yarn test +``` + **Notes** Always skipping is useful when you have a `lefthook-local.yml` config and you don't want to run some commands locally. So you just overwrite the `skip` option for them to be `true`. diff --git a/internal/config/command.go b/internal/config/command.go index 79a70f2e..084255d1 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -40,7 +40,8 @@ func (c Command) Validate() error { } func (c Command) DoSkip(gitState git.State) bool { - return doSkip(gitState, c.Skip, c.Only) + skipChecker := NewSkipChecker(nil) + return skipChecker.DoSkip(gitState, c.Skip, c.Only) } type commandRunReplace struct { diff --git a/internal/config/exec.go b/internal/config/exec.go new file mode 100644 index 00000000..7f82b8dc --- /dev/null +++ b/internal/config/exec.go @@ -0,0 +1,34 @@ +package config + +import ( + "os/exec" + "strings" +) + +type Exec interface { + Cmd(commandLine string) bool +} + +type osExec struct{} + +// NewOsExec returns an object that executes given commands in the OS. +func NewOsExec() Exec { + return &osExec{} +} + +// Cmd runs plain string command. It checks only exit code and returns bool value. +func (o *osExec) Cmd(commandLine string) bool { + parts := strings.Fields(commandLine) + + if len(parts) == 0 { + return false + } + + cmdName := parts[0] + cmdArgs := parts[1:] + + cmd := exec.Command(cmdName, cmdArgs...) + err := cmd.Run() + + return err == nil +} diff --git a/internal/config/hook.go b/internal/config/hook.go index 692cc5cb..94ba2ce0 100644 --- a/internal/config/hook.go +++ b/internal/config/hook.go @@ -43,7 +43,8 @@ func (h *Hook) Validate() error { } func (h *Hook) DoSkip(gitState git.State) bool { - return doSkip(gitState, h.Skip, h.Only) + skipChecker := NewSkipChecker(nil) + return skipChecker.DoSkip(gitState, h.Skip, h.Only) } func unmarshalHooks(base, extra *viper.Viper) (*Hook, error) { diff --git a/internal/config/script.go b/internal/config/script.go index a2070dbe..d212d5b9 100644 --- a/internal/config/script.go +++ b/internal/config/script.go @@ -24,7 +24,8 @@ type Script struct { } func (s Script) DoSkip(gitState git.State) bool { - return doSkip(gitState, s.Skip, s.Only) + skipChecker := NewSkipChecker(nil) + return skipChecker.DoSkip(gitState, s.Skip, s.Only) } type scriptRunnerReplace struct { diff --git a/internal/config/skip.go b/internal/config/skip.go index 9b52f3bd..eceb6993 100644 --- a/internal/config/skip.go +++ b/internal/config/skip.go @@ -4,47 +4,90 @@ import ( "github.com/gobwas/glob" "github.com/evilmartians/lefthook/internal/git" + "github.com/evilmartians/lefthook/internal/log" ) -func doSkip(gitState git.State, skip, only interface{}) bool { +type SkipChecker struct { + Executor Exec +} + +func NewSkipChecker(executor Exec) *SkipChecker { + if executor == nil { + executor = NewOsExec() + } + + return &SkipChecker{Executor: executor} +} + +func (sc *SkipChecker) DoSkip(gitState git.State, skip interface{}, only interface{}) bool { if skip != nil { - if matches(gitState, skip) { + if sc.matches(gitState, skip) { return true } } if only != nil { - return !matches(gitState, only) + return !sc.matches(gitState, only) } return false } -func matches(gitState git.State, value interface{}) bool { +func (sc *SkipChecker) matches(gitState git.State, value interface{}) bool { switch typedValue := value.(type) { case bool: return typedValue case string: return typedValue == gitState.Step case []interface{}: - for _, state := range typedValue { - switch typedState := state.(type) { - case string: - if typedState == gitState.Step { - return true - } - case map[string]interface{}: - ref := typedState["ref"].(string) - if ref == gitState.Branch { - return true - } - - g := glob.MustCompile(ref) - if g.Match(gitState.Branch) { - return true - } + return sc.matchesSlices(gitState, typedValue) + } + return false +} + +func (sc *SkipChecker) matchesSlices(gitState git.State, slice []interface{}) bool { + for _, state := range slice { + switch typedState := state.(type) { + case string: + if typedState == gitState.Step { + return true + } + case map[string]interface{}: + if sc.matchesRef(gitState, typedState) { + return true + } + + if sc.matchesCommands(typedState) { + return true } } } + return false } + +func (sc *SkipChecker) matchesRef(gitState git.State, typedState map[string]interface{}) bool { + ref, ok := typedState["ref"].(string) + if !ok { + return false + } + + if ref == gitState.Branch { + return true + } + + g := glob.MustCompile(ref) + + return g.Match(gitState.Branch) +} + +func (sc *SkipChecker) matchesCommands(typedState map[string]interface{}) bool { + commandLine, ok := typedState["run"].(string) + if !ok { + return false + } + + log.Debug("[lefthook] skip/only cmd: ", commandLine) + + return sc.Executor.Cmd(commandLine) +} diff --git a/internal/config/skip_test.go b/internal/config/skip_test.go index d4d3c6f3..9fe247da 100644 --- a/internal/config/skip_test.go +++ b/internal/config/skip_test.go @@ -6,7 +6,15 @@ import ( "github.com/evilmartians/lefthook/internal/git" ) +type mockExecutor struct{} + +func (mc mockExecutor) Cmd(cmd string) bool { + return cmd == "success" +} + func TestDoSkip(t *testing.T) { + skipChecker := NewSkipChecker(mockExecutor{}) + for _, tt := range [...]struct { name string state git.State @@ -111,9 +119,27 @@ func TestDoSkip(t *testing.T) { only: "rebase", skipped: true, }, + { + name: "when skip with run command", + state: git.State{}, + skip: []interface{}{map[string]interface{}{"run": "success"}}, + skipped: true, + }, + { + name: "when skip with multi-run command", + state: git.State{Branch: "feat"}, + skip: []interface{}{map[string]interface{}{"run": "success", "ref": "feat"}}, + skipped: true, + }, + { + name: "when only with run command", + state: git.State{}, + only: []interface{}{map[string]interface{}{"run": "fail"}}, + skipped: true, + }, } { t.Run(tt.name, func(t *testing.T) { - if doSkip(tt.state, tt.skip, tt.only) != tt.skipped { + if skipChecker.DoSkip(tt.state, tt.skip, tt.only) != tt.skipped { t.Errorf("Expected: %v, Was %v", tt.skipped, !tt.skipped) } }) From c96d3621a5dd2cf6d10530750ab21f16fc6da0a1 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Tue, 5 Mar 2024 11:20:13 +0100 Subject: [PATCH 2/9] fix by codereview --- internal/config/command.go | 2 +- internal/config/hook.go | 2 +- internal/config/script.go | 4 ++-- internal/config/{skip.go => skip_checker.go} | 8 +++++--- internal/config/{skip_test.go => skip_checker_test.go} | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) rename internal/config/{skip.go => skip_checker.go} (87%) rename internal/config/{skip_test.go => skip_checker_test.go} (98%) diff --git a/internal/config/command.go b/internal/config/command.go index 084255d1..d3ebbbf2 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -41,7 +41,7 @@ func (c Command) Validate() error { func (c Command) DoSkip(gitState git.State) bool { skipChecker := NewSkipChecker(nil) - return skipChecker.DoSkip(gitState, c.Skip, c.Only) + return skipChecker.Check(gitState, c.Skip, c.Only) } type commandRunReplace struct { diff --git a/internal/config/hook.go b/internal/config/hook.go index 94ba2ce0..c7319403 100644 --- a/internal/config/hook.go +++ b/internal/config/hook.go @@ -44,7 +44,7 @@ func (h *Hook) Validate() error { func (h *Hook) DoSkip(gitState git.State) bool { skipChecker := NewSkipChecker(nil) - return skipChecker.DoSkip(gitState, h.Skip, h.Only) + return skipChecker.Check(gitState, h.Skip, h.Only) } func unmarshalHooks(base, extra *viper.Viper) (*Hook, error) { diff --git a/internal/config/script.go b/internal/config/script.go index d212d5b9..085b65f7 100644 --- a/internal/config/script.go +++ b/internal/config/script.go @@ -24,8 +24,8 @@ type Script struct { } func (s Script) DoSkip(gitState git.State) bool { - skipChecker := NewSkipChecker(nil) - return skipChecker.DoSkip(gitState, s.Skip, s.Only) + skipChecker := NewSkipChecker(NewOsExec()) + return skipChecker.Check(gitState, s.Skip, s.Only) } type scriptRunnerReplace struct { diff --git a/internal/config/skip.go b/internal/config/skip_checker.go similarity index 87% rename from internal/config/skip.go rename to internal/config/skip_checker.go index eceb6993..581610f7 100644 --- a/internal/config/skip.go +++ b/internal/config/skip_checker.go @@ -19,7 +19,7 @@ func NewSkipChecker(executor Exec) *SkipChecker { return &SkipChecker{Executor: executor} } -func (sc *SkipChecker) DoSkip(gitState git.State, skip interface{}, only interface{}) bool { +func (sc *SkipChecker) Check(gitState git.State, skip interface{}, only interface{}) bool { if skip != nil { if sc.matches(gitState, skip) { return true @@ -87,7 +87,9 @@ func (sc *SkipChecker) matchesCommands(typedState map[string]interface{}) bool { return false } - log.Debug("[lefthook] skip/only cmd: ", commandLine) + result := sc.Executor.Cmd(commandLine) - return sc.Executor.Cmd(commandLine) + log.Debugf("[lefthook] skip/only cmd: %s, result: %t", commandLine, result) + + return result } diff --git a/internal/config/skip_test.go b/internal/config/skip_checker_test.go similarity index 98% rename from internal/config/skip_test.go rename to internal/config/skip_checker_test.go index 9fe247da..4956859f 100644 --- a/internal/config/skip_test.go +++ b/internal/config/skip_checker_test.go @@ -139,7 +139,7 @@ func TestDoSkip(t *testing.T) { }, } { t.Run(tt.name, func(t *testing.T) { - if skipChecker.DoSkip(tt.state, tt.skip, tt.only) != tt.skipped { + if skipChecker.Check(tt.state, tt.skip, tt.only) != tt.skipped { t.Errorf("Expected: %v, Was %v", tt.skipped, !tt.skipped) } }) From 64257bdc490e1a948541a381eb4931db947544f0 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Thu, 7 Mar 2024 11:34:57 +0300 Subject: [PATCH 3/9] chore: add a testscript --- testdata/skip_run.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 testdata/skip_run.txt diff --git a/testdata/skip_run.txt b/testdata/skip_run.txt new file mode 100644 index 00000000..8175adc8 --- /dev/null +++ b/testdata/skip_run.txt @@ -0,0 +1,26 @@ +exec git init +exec git add -A +exec lefthook run skip +! stdout 'Ha-ha!' +exec lefthook run no-skip +stdout 'Ha-ha!' + +-- lefthook.yml -- +skip_output: + - skips + - meta + - summary + - execution_info +skip: + skip: + - run: test 1 -eq 1 + commands: + echo: + run: echo 'Ha-ha!' + +no-skip: + skip: + - run: "[ 1 -eq 0 ]" + commands: + echo: + run: echo 'Ha-ha!' From fce5f53a88394ce7048e9f1497b0d47222ad158b Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Mon, 11 Mar 2024 13:22:29 +0100 Subject: [PATCH 4/9] call skip commands via shell --- internal/config/command.go | 2 +- internal/config/exec.go | 10 ++-------- internal/config/hook.go | 2 +- testdata/skip_run.txt | 12 ++++++++++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/config/command.go b/internal/config/command.go index d3ebbbf2..1d47ac9a 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -40,7 +40,7 @@ func (c Command) Validate() error { } func (c Command) DoSkip(gitState git.State) bool { - skipChecker := NewSkipChecker(nil) + skipChecker := NewSkipChecker(NewOsExec()) return skipChecker.Check(gitState, c.Skip, c.Only) } diff --git a/internal/config/exec.go b/internal/config/exec.go index 7f82b8dc..99d3d06c 100644 --- a/internal/config/exec.go +++ b/internal/config/exec.go @@ -2,7 +2,6 @@ package config import ( "os/exec" - "strings" ) type Exec interface { @@ -18,16 +17,11 @@ func NewOsExec() Exec { // Cmd runs plain string command. It checks only exit code and returns bool value. func (o *osExec) Cmd(commandLine string) bool { - parts := strings.Fields(commandLine) - - if len(parts) == 0 { + if commandLine == "" { return false } - cmdName := parts[0] - cmdArgs := parts[1:] - - cmd := exec.Command(cmdName, cmdArgs...) + cmd := exec.Command("sh", "-c", commandLine) err := cmd.Run() return err == nil diff --git a/internal/config/hook.go b/internal/config/hook.go index c7319403..3a958c72 100644 --- a/internal/config/hook.go +++ b/internal/config/hook.go @@ -43,7 +43,7 @@ func (h *Hook) Validate() error { } func (h *Hook) DoSkip(gitState git.State) bool { - skipChecker := NewSkipChecker(nil) + skipChecker := NewSkipChecker(NewOsExec()) return skipChecker.Check(gitState, h.Skip, h.Only) } diff --git a/testdata/skip_run.txt b/testdata/skip_run.txt index 8175adc8..0719c886 100644 --- a/testdata/skip_run.txt +++ b/testdata/skip_run.txt @@ -4,6 +4,11 @@ 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: @@ -24,3 +29,10 @@ no-skip: commands: echo: run: echo 'Ha-ha!' + +skip-var: + skip: + - run: test -z $VAR + commands: + echo: + run: echo 'Ha-ha!' From fedebb0972a1caabc3c5a3dbec4ae4e4341a5ae6 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Mon, 11 Mar 2024 14:19:20 +0100 Subject: [PATCH 5/9] try to use command for windows --- internal/config/exec.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/config/exec.go b/internal/config/exec.go index 99d3d06c..54a8f6e9 100644 --- a/internal/config/exec.go +++ b/internal/config/exec.go @@ -2,6 +2,7 @@ package config import ( "os/exec" + "runtime" ) type Exec interface { @@ -21,7 +22,13 @@ func (o *osExec) Cmd(commandLine string) bool { return false } - cmd := exec.Command("sh", "-c", commandLine) + var cmd *exec.Cmd + if runtime.GOOS == "windows" { + cmd = exec.Command("cmd", "/C", commandLine) + } else { + cmd = exec.Command("sh", "-c", commandLine) + } + err := cmd.Run() return err == nil From dc3cf4d683146aad3152359231c62096a2db3e2b Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Tue, 12 Mar 2024 09:53:11 +0300 Subject: [PATCH 6/9] ci: run integration tests on Windows --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e78f6669..50c65239 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: strategy: matrix: go-version: [1.21.x] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} env: GOCOVERDIR: ${{ github.workspace }}/_icoverdir_ @@ -91,5 +91,5 @@ jobs: steps: - uses: coverallsapp/github-action@v2 with: - carryforward: "integration-1.21.x ubuntu-latest,integration-1.21.x macos-latest,1.21.x ubuntu-latest,1.21.x macos-latest,1.21.x windows-latest" + carryforward: "integration-1.21.x ubuntu-latest,integration-1.21.x macos-latest,integration-1.21.x windows-latest,1.21.x ubuntu-latest,1.21.x macos-latest,1.21.x windows-latest" parallel-finished: true From a27cd6d527b26e774b59fb0131dccd49e70d9590 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Tue, 12 Mar 2024 10:48:50 +0100 Subject: [PATCH 7/9] checking windows section in testscript --- testdata/skip_run.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/testdata/skip_run.txt b/testdata/skip_run.txt index 0719c886..b9f7ec74 100644 --- a/testdata/skip_run.txt +++ b/testdata/skip_run.txt @@ -4,11 +4,17 @@ exec lefthook run skip ! stdout 'Ha-ha!' exec lefthook run no-skip stdout 'Ha-ha!' -exec lefthook run skip-var -! stdout 'Ha-ha!' + +[unix] exec lefthook run skip-var + ! stdout 'Ha-ha!' +[windows] exec lefthook run skip-var-windows + ! stdout 'Ha-ha!' + env VAR=1 -exec lefthook run skip-var -stdout 'Ha-ha!' +[unix] exec lefthook run skip-var + stdout 'Ha-ha!' +[windows] exec lefthook run skip-var-windows + stdout 'Ha-ha!' -- lefthook.yml -- skip_output: @@ -36,3 +42,10 @@ 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!' From 9a362342dcffb6642b9cf83768c935840436a6fc Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Tue, 12 Mar 2024 10:57:20 +0100 Subject: [PATCH 8/9] test another syntax testscript --- testdata/skip_run.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testdata/skip_run.txt b/testdata/skip_run.txt index b9f7ec74..0db312bb 100644 --- a/testdata/skip_run.txt +++ b/testdata/skip_run.txt @@ -6,13 +6,11 @@ exec lefthook run no-skip stdout 'Ha-ha!' [unix] exec lefthook run skip-var - ! stdout 'Ha-ha!' [windows] exec lefthook run skip-var-windows - ! stdout 'Ha-ha!' +! stdout 'Ha-ha!' env VAR=1 [unix] exec lefthook run skip-var - stdout 'Ha-ha!' [windows] exec lefthook run skip-var-windows stdout 'Ha-ha!' From 348e67cafd98815516157e85fcace9eefd8bc4f0 Mon Sep 17 00:00:00 2001 From: prog-supdex Date: Tue, 12 Mar 2024 11:15:30 +0100 Subject: [PATCH 9/9] work with windows --- internal/config/exec.go | 2 +- testdata/add.txt | 2 ++ testdata/dump.txt | 2 ++ testdata/hide_unstaged.txt | 2 ++ testdata/remote.txt | 2 ++ testdata/remotes.txt | 2 ++ testdata/run_interrupt.txt | 2 ++ testdata/sh_syntax_in_files.txt | 3 +++ testdata/skip_run.txt | 17 ++++--------- testdata/skip_run_windows.txt | 42 +++++++++++++++++++++++++++++++++ 10 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 testdata/skip_run_windows.txt 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/add.txt b/testdata/add.txt index 4aa86233..da9e0e95 100644 --- a/testdata/add.txt +++ b/testdata/add.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec lefthook add pre-commit ! stderr . diff --git a/testdata/dump.txt b/testdata/dump.txt index 3857f0d4..5a5559e3 100644 --- a/testdata/dump.txt +++ b/testdata/dump.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec lefthook dump cmp stdout lefthook-dumped.yml diff --git a/testdata/hide_unstaged.txt b/testdata/hide_unstaged.txt index 4147604e..5aa67510 100644 --- a/testdata/hide_unstaged.txt +++ b/testdata/hide_unstaged.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec lefthook install exec git config user.email "you@example.com" diff --git a/testdata/remote.txt b/testdata/remote.txt index 72435af1..df0c246b 100644 --- a/testdata/remote.txt +++ b/testdata/remote.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec lefthook install diff --git a/testdata/remotes.txt b/testdata/remotes.txt index 7858b6e3..beffc20f 100644 --- a/testdata/remotes.txt +++ b/testdata/remotes.txt @@ -1,3 +1,5 @@ +[windows] skip + exec git init exec lefthook install diff --git a/testdata/run_interrupt.txt b/testdata/run_interrupt.txt index 9103d014..2716c53d 100644 --- a/testdata/run_interrupt.txt +++ b/testdata/run_interrupt.txt @@ -1,3 +1,5 @@ +[windows] skip + chmod 0700 hook.sh chmod 0700 commit-with-interrupt.sh exec git init diff --git a/testdata/sh_syntax_in_files.txt b/testdata/sh_syntax_in_files.txt index a45c9a25..b65a7cb7 100644 --- a/testdata/sh_syntax_in_files.txt +++ b/testdata/sh_syntax_in_files.txt @@ -1,9 +1,12 @@ +[windows] skip + exec git init exec lefthook install exec git config user.email "you@example.com" exec git config user.name "Your Name" exec lefthook run echo_files + stdout '1.txt 10.txt' -- lefthook.yml -- 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..f5d6fd82 --- /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 +! 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!'