From 44cf715b1cf117639db3db7c27c92f8929a56ccf Mon Sep 17 00:00:00 2001 From: Fabio Napoleoni Date: Fri, 31 Mar 2023 16:52:34 +0200 Subject: [PATCH] Allow extra hooks also in local config --- internal/config/load.go | 3 ++- internal/config/load_test.go | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/internal/config/load.go b/internal/config/load.go index 45112574..447acdef 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -186,7 +186,8 @@ func unmarshalConfigs(base, extra *viper.Viper, c *Config) error { // For extra non-git hooks. // This behavior may be deprecated in next versions. - for _, maybeHook := range base.AllKeys() { + // Notice that with append we're allowing extra hooks to be added in local config + for _, maybeHook := range append(base.AllKeys(), extra.AllKeys()...) { if !hookKeyRegexp.MatchString(maybeHook) { continue } diff --git a/internal/config/load_test.go b/internal/config/load_test.go index b98ebf88..241a7779 100644 --- a/internal/config/load_test.go +++ b/internal/config/load_test.go @@ -152,6 +152,43 @@ tests: tests: run: go test ./... +lints: + scripts: + "linter.sh": + runner: bash +`, + result: &Config{ + SourceDir: DefaultSourceDir, + SourceDirLocal: DefaultSourceDirLocal, + Colors: DefaultColorsEnabled, + Hooks: map[string]*Hook{ + "tests": { + Parallel: false, + Commands: map[string]*Command{ + "tests": { + Run: "go test ./...", + }, + }, + }, + "lints": { + Scripts: map[string]*Script{ + "linter.sh": { + Runner: "bash", + }, + }, + }, + }, + }, + }, + { + name: "with extra hooks only in local config", + global: ` +tests: + commands: + tests: + run: go test ./... +`, + local: ` lints: scripts: "linter.sh":