Skip to content

Commit

Permalink
feat: add run --no-auto-install flag (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed May 13, 2024
1 parent 5c6d8ae commit 6965783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type RunArgs struct {
AllFiles bool
FilesFromStdin bool
Force bool
NoAutoInstall bool
Files []string
RunOnlyCommands []string
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6965783

Please sign in to comment.