Skip to content

Commit

Permalink
chore: skip summary separator if nothing is printed
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Nov 14, 2023
1 parent d527c1f commit 4294d78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions internal/lefthook/lefthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
)

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

var lefthookContentRegexp = regexp.MustCompile("LEFTHOOK")
Expand Down Expand Up @@ -94,7 +95,7 @@ func (l *Lefthook) cleanHook(hook string, force bool) error {
}

// Check if .old file already exists before renaming.
exists, err = afero.Exists(l.Fs, hookPath+".old")
exists, err = afero.Exists(l.Fs, hookPath+oldHookPostfix)
if err != nil {
return err
}
Expand All @@ -107,7 +108,7 @@ func (l *Lefthook) cleanHook(hook string, force bool) error {
}
}

err = l.Fs.Rename(hookPath, hookPath+".old")
err = l.Fs.Rename(hookPath, hookPath+oldHookPostfix)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ func printSummary(
results []run.Result,
logSettings log.SkipSettings,
) {
summaryPrint := log.Separate

if logSettings.SkipExecution() || (logSettings.SkipExecutionInfo() && logSettings.SkipExecutionOutput()) {
summaryPrint = func(s string) { log.Info(s) }
}

if len(results) == 0 {
if !logSettings.SkipEmptySummary() {
log.Separate(
summaryPrint(
fmt.Sprintf(
"%s %s %s",
log.Cyan("summary:"),
Expand All @@ -195,7 +201,7 @@ func printSummary(
return
}

log.Separate(
summaryPrint(
log.Cyan("summary: ") + log.Gray(fmt.Sprintf("(done in %.2f seconds)", duration.Seconds())),
)

Expand Down

0 comments on commit 4294d78

Please sign in to comment.