Skip to content

Commit

Permalink
fix: LEFTHOOK_VERBOSE properly overrides --verbose flag (#521)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Kiselev <mrexox@evilmartians.com>
  • Loading branch information
hyperupcall and mrexox authored Jul 17, 2023
1 parent 27426fa commit 193190b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 9 additions & 1 deletion internal/lefthook/lefthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lefthook
import (
"bufio"
"fmt"
"os"
"path/filepath"
"regexp"

Expand All @@ -13,7 +14,10 @@ import (
"github.com/evilmartians/lefthook/internal/templates"
)

const hookFileMode = 0o755
const (
hookFileMode = 0o755
envVerbose = "LEFTHOOK_VERBOSE" // keep all output
)

var lefthookContentRegexp = regexp.MustCompile("LEFTHOOK")

Expand All @@ -35,6 +39,10 @@ type Lefthook struct {

// New returns an instance of Lefthook.
func initialize(opts *Options) (*Lefthook, error) {
if os.Getenv(envVerbose) == "1" || os.Getenv(envVerbose) == "true" {
opts.Verbose = true
}

if opts.Verbose {
log.SetLevel(log.DebugLevel)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import (
)

const (
envEnabled = "LEFTHOOK" // "0", "false"
envSkipOutput = "LEFTHOOK_QUIET" // "meta,success,failure,summary,skips,execution,execution_out,execution_info"
envVerbose = "LEFTHOOK_VERBOSE" // keep all output
envEnabled = "LEFTHOOK" // "0", "false"
envSkipOutput = "LEFTHOOK_QUIET" // "meta,success,failure,summary,skips,execution,execution_out,execution_info"
)

type RunArgs struct {
Expand All @@ -39,7 +38,7 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error {
}

var verbose bool
if l.Verbose || os.Getenv(envVerbose) == "1" || os.Getenv(envVerbose) == "true" {
if l.Verbose {
log.SetLevel(log.DebugLevel)
verbose = true
}
Expand Down

0 comments on commit 193190b

Please sign in to comment.