Skip to content

Commit 882159f

Browse files
authored
fix: don't install custom hooks to hooks dir (#1246)
1 parent 037fcdc commit 882159f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

internal/command/install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,16 @@ func (l *Lefthook) createHooksIfNeeded(cfg *config.Config, hooks []string, force
298298
continue
299299
}
300300

301-
hookNames = append(hookNames, hook)
302-
303301
if err = l.cleanHook(hook, force); err != nil {
304302
return fmt.Errorf("could not replace the hook: %w", err)
305303
}
306304

305+
if _, ok := config.AvailableHooks[hook]; !ok {
306+
continue
307+
}
308+
309+
hookNames = append(hookNames, hook)
310+
307311
templateArgs := templates.Args{
308312
Rc: cfg.Rc,
309313
AssertLefthookInstalled: cfg.AssertLefthookInstalled,

internal/command/install_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,36 @@ post-commit:
213213
infoPath(config.ChecksumFileName),
214214
},
215215
},
216+
{
217+
name: "with custom hook",
218+
config: `
219+
my-custom-hook:
220+
commands:
221+
custom:
222+
run: echo 'Hello from custom!'
223+
`,
224+
wantNotExist: []string{
225+
hookPath("my-custom-hook"),
226+
},
227+
},
228+
{
229+
name: "with custom existing hook",
230+
config: `
231+
my-custom-hook:
232+
commands:
233+
custom:
234+
run: echo 'Hello from custom!'
235+
`,
236+
existingFiles: map[string]string{
237+
hookPath("my-custom-hook"): "",
238+
},
239+
wantExist: []string{
240+
hookPath("my-custom-hook.old"),
241+
},
242+
wantNotExist: []string{
243+
hookPath("my-custom-hook"),
244+
},
245+
},
216246
{
217247
name: "with unfetched remote",
218248
config: `

0 commit comments

Comments
 (0)