Skip to content

Commit 6cb576e

Browse files
committed
chore: fancy wording and indentation for hits
1 parent ec7e8e1 commit 6cb576e

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

internal/command/install.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ type InstallArgs struct {
4141
}
4242

4343
func (l *Lefthook) Install(ctx context.Context, args InstallArgs, hooks []string) error {
44-
// Check for core.hooksPath configuration
45-
localHooksPath, globalHooksPath := l.getHooksPathConfig()
46-
47-
if err := l.ensureNoHooksPath(localHooksPath, globalHooksPath, args.Force, args.ResetHooksPath); err != nil {
44+
if err := l.ensureHooksPathUnset(args.Force, args.ResetHooksPath); err != nil {
4845
return err
4946
}
5047

@@ -477,8 +474,13 @@ func (l *Lefthook) getHooksPathConfig() (local, global string) {
477474
return
478475
}
479476

480-
// ensureNoHooksPath ensures core.hooksPath is not configured.
481-
func (l *Lefthook) ensureNoHooksPath(local, global string, force, resetHooksPath bool) error {
477+
// ensureHooksPathUnset ensures core.hooksPath is not configured.
478+
//
479+
// In general using lefthook doesn't make sense with global hooks.
480+
// Local hooks make sense only in terms of migratio from other hook managers.
481+
func (l *Lefthook) ensureHooksPathUnset(force, resetHooksPath bool) error {
482+
local, global := l.getHooksPathConfig()
483+
482484
hasLocal := len(local) > 0
483485
hasGlobal := len(global) > 0
484486

@@ -491,26 +493,23 @@ func (l *Lefthook) ensureNoHooksPath(local, global string, force, resetHooksPath
491493
return formatHooksPathError(local, global)
492494
}
493495

494-
// Warn about configured core.hooksPath
495496
if hasLocal {
496-
log.Warnf("core.hooksPath is set locally to '%s'.", local)
497+
log.Warnf("core.hooksPath is set locally to '%s'", local)
497498
}
498499
if hasGlobal {
499-
log.Warnf("core.hooksPath is set globally to '%s'.", global)
500+
log.Warnf("core.hooksPath is set globally to '%s'", global)
500501
}
501502

502-
// If resetHooksPath is true, unset the conflicting configurations.
503503
if resetHooksPath {
504504
return l.unsetHooksPathConfig(local, global)
505505
}
506506

507-
// If force is true, proceed with installation anyway (without unsetting).
508-
// Determine path: use global path if only global is defined, otherwise use local path
507+
// Local setting takes precedence.
509508
path := local
510509
if !hasLocal && hasGlobal {
511510
path = global
512511
}
513-
log.Warnf("Installing lefthook anyway in '%s'.", path)
512+
log.Warnf("Installing hooks anyway in '%s'", path)
514513

515514
return nil
516515
}
@@ -523,25 +522,29 @@ func formatHooksPathError(local, global string) error {
523522
hasGlobal := len(global) > 0
524523

525524
if hasLocal {
526-
errMsg.WriteString(fmt.Sprintf("core.hooksPath is set locally to '%s'.\n", local))
527-
hints = append(hints, "hint: git config --unset-all --local core.hooksPath")
525+
errMsg.WriteString(fmt.Sprintf("core.hooksPath is set locally to '%s'\n", local))
526+
hints = append(hints, "hint: git config --unset-all --local core.hooksPath")
528527
}
529528
if hasGlobal {
530-
errMsg.WriteString(fmt.Sprintf("core.hooksPath is set globally to '%s'.\n", global))
531-
hints = append(hints, "hint: git config --unset-all --global core.hooksPath")
529+
errMsg.WriteString(fmt.Sprintf("core.hooksPath is set globally to '%s'\n", global))
530+
hints = append(hints, "hint: git config --unset-all --global core.hooksPath")
532531
}
533-
534-
errMsg.WriteString("hint: Run these commands to remove it:\n")
532+
errMsg.WriteString("\n")
533+
errMsg.WriteString("hint: Unset it:\n")
534+
errMsg.WriteString("hint:\n")
535535
errMsg.WriteString(strings.Join(hints, "\n"))
536-
errMsg.WriteString("\nhint: Or run lefthook with --reset-hooks-path to automatically unset it:\n")
537-
errMsg.WriteString("hint: lefthook install --reset-hooks-path\n")
536+
errMsg.WriteString("\nhint:\n")
537+
errMsg.WriteString("hint: Or run lefthook with --reset-hooks-path to automatically unset it:\n")
538+
errMsg.WriteString("hint:\n")
539+
errMsg.WriteString("hint: lefthook install --reset-hooks-path\n")
538540

539541
// Determine path: use global path if only global is defined, otherwise use local path
540542
path := local
541543
if !hasLocal && hasGlobal {
542544
path = global
543545
}
544-
errMsg.WriteString(fmt.Sprintf("hint: Use option --force to install lefthook it anyway in '%s'.", path))
546+
errMsg.WriteString("hint:\n")
547+
errMsg.WriteString(fmt.Sprintf("hint: Run 'lefthook install --force' to install hooks anyway in '%s'.", path))
545548

546549
return errors.New(errMsg.String())
547550
}

0 commit comments

Comments
 (0)