evilmartians / lefthook

Fast and powerful Git hooks manager for any type of projects.
MIT License
4.66k stars 211 forks source link

can't evaluate field Extension in type string #766

Closed apfohl closed 1 month ago

apfohl commented 1 month ago

:wrench: Summary

When running lefthook install the hook.tmpl can not be generated due to this error:

panic: template: hook.tmpl:50:69: executing "hook.tmpl" at <.Extension>: can't evaluate field Extension in type string

goroutine 1 [running]:
github.com/evilmartians/lefthook/internal/templates.Hook({0x7f9f21, 0xa}, {{0x0, 0x0}, 0x0, {0xc0002a8af0, 0x1, 0x1}})
        /home/andreas/code/lefthook/internal/templates/templates.go:41 +0x1d3
github.com/evilmartians/lefthook/internal/lefthook.(*Lefthook).addHook(0xc00002dad0, {0x7f9f21, 0xa}, {{0x0, 0x0}, 0x0, {0xc0002a8af0, 0x1, 0x1}})
        /home/andreas/code/lefthook/internal/lefthook/lefthook.go:124 +0xe7
github.com/evilmartians/lefthook/internal/lefthook.(*Lefthook).createHooksIfNeeded(0xc00002dad0, 0xc000000240, 0x40?, 0x0)
        /home/andreas/code/lefthook/internal/lefthook/install.go:199 +0x6a8
github.com/evilmartians/lefthook/internal/lefthook.(*Lefthook).Install(0xc00002dad0, 0x0)
        /home/andreas/code/lefthook/internal/lefthook/install.go:74 +0x1b5
github.com/evilmartians/lefthook/internal/lefthook.Install(0x0?, 0x0)
        /home/andreas/code/lefthook/internal/lefthook/install.go:45 +0x32
github.com/evilmartians/lefthook/cmd.newInstallCmd.func1(0xc0000e0700?, {0xbdcc00?, 0x4?, 0x7f7639?})
        /home/andreas/code/lefthook/cmd/install.go:19 +0x1e
github.com/spf13/cobra.(*Command).execute(0xc0001a2908, {0xbdcc00, 0x0, 0x0})
        /home/andreas/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001a2008)
        /home/andreas/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /home/andreas/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/evilmartians/lefthook/cmd.Lefthook()
        /home/andreas/code/lefthook/cmd/lefthook.go:8 +0x1c
main.main()
        /home/andreas/code/lefthook/main.go:10 +0x13

Lefthook version

1.7.0

Steps to reproduce

Running lefthook install on my Ubuntu 22.04 system in the OpenProject repository.

Expected results

It should install the hooks.

Actual results

See error message above.

Possible Solution

Replace .Extension in hook.tmpl with $extension below range call.

Logs / Screenshots

│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] err: <nil>
│ [lefthook] out: /home/andreas/code/openproject

│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks

│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info

│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] err: <nil>
│ [lefthook] out: .git

│ [lefthook] cmd: [git hash-object -t tree /dev/null]
│ [lefthook] err: <nil>
│ [lefthook] out: 4b825dc642cb6eb9a060e54bf8d69288fbee4904

│ Searching config in:/home/andreas/code/openproject
mrexox commented 1 month ago

Thank you for capturing this issue! Will release the fix ASAP