gopre-commit-hookpre-commitpre-commit.com

Executable not found while running custom pre-commit hook written in Go


I am trying to build a custom pre-commit hook written in Go. It should run on python file.

The project has the following architecture:

comche/
├── cmd/
│   └── main.go
├── scripts/
│   └── main -> build with "go build -o scripts/ cmd/main.go"
├── .pre-commit-hooks.yaml
├── go.mod
├── .gitignore
└── README.md

I have setup the .pre-commit-hooks.yaml has follow:

- id: comche
  name: comche
  description: "Check Python files for TODO, BUG, and FIXME comments"
  entry: main
  language: golang
  language_version: system
  types: [python]
  additional_dependencies: []

But when I install/setup the pre-commit on another repo to make test, I have the following error: "Executable main not found"!

Note that the hook is run by pre-commit and the installation works well, but when I commit a Python file (which trigger my hook), I have the previous error.

I have tried to change the entry point, such as, ./scripts/main, cmd/main.go, main.go or comche/scripts/main without success.

Do you have any id of what I am missing?

Thanks in advance for your help!


Solution

  • for language: golang the executables must be present by running go install ./... -- your custom go build -o scripts command is not the convention that go follows and so your executable isn't being created in the way you expect

    you'll need to make your go source tree adhere to go's standard conventions for executables in order for them to work with pre-commit


    disclaimer: I wrote pre-commit