Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEFTHOOK_VERBOSE properly overrides --verbose flag #521

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading