diff --git a/cmd/run.go b/cmd/run.go index 9de6a8d7..a07d2985 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -58,6 +58,11 @@ func newRunCmd(opts *lefthook.Options) *cobra.Command { "run hooks on all files", ) + runCmd.Flags().BoolVar( + &runArgs.NoAutoInstall, "no-auto-install", false, + "skip updating git hooks", + ) + runCmd.Flags().BoolVar( &runArgs.FilesFromStdin, "files-from-stdin", false, "get files from standard input, null-separated", diff --git a/internal/lefthook/run.go b/internal/lefthook/run.go index 5a7f4f80..59b526fb 100644 --- a/internal/lefthook/run.go +++ b/internal/lefthook/run.go @@ -28,6 +28,7 @@ type RunArgs struct { AllFiles bool FilesFromStdin bool Force bool + NoAutoInstall bool Files []string RunOnlyCommands []string } @@ -94,12 +95,14 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error { ) } - // This line controls updating the git hook if config has changed - if err = l.createHooksIfNeeded(cfg, true, false); err != nil { - log.Warn( - `⚠️ There was a problem with synchronizing git hooks. + if !args.NoAutoInstall { + // This line controls updating the git hook if config has changed + if err = l.createHooksIfNeeded(cfg, true, false); err != nil { + log.Warn( + `⚠️ There was a problem with synchronizing git hooks. Run 'lefthook install' manually.`, - ) + ) + } } // Find the hook