Gofmt git commit hook

Trevor.Conn@...
 

https://tip.golang.org/misc/git/pre-commit

 

Per our discussion in the Core WG call yesterday, I’m working today on looking for code quality tools that we can easily integrate and that will do as many of the required checks prior to merge as possible. I found the above git pre-commit script which can be used to run gofmt prior to commit on the client side. Sample output for poorly formatted code when I try to commit looks like this:

 

Go files must be formatted with gofmt. Please run:

  gofmt -w /Users/tconn/go/src/github.com/edgexfoundry/edgex-go/cmd/core-data/main.go

 

I can't commit until I fix the problems. The only downside, as I understand it, is that it relies on the developer to create the scripts and give it execute permissions. Plus I don’t understand how this can be source controlled. It looks like there are server-side git hooks as well.

 

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

 

Would this be more appropriate as a server-side hook that runs during a push? If so, what’s the effort in setting that up in all Go repos? How about when we create new Go repos?

 

The script is linked from a larger blog post:

https://blog.golang.org/go-fmt-your-code


Using this strategy we could also wire in golint and other tools. Thoughts?


Trevor Conn
Senior Principal Software Engineer
Dell Technologies | IoT DellTech
Trevor_Conn@...
Round Rock, TX  USA

Join EdgeX-TSC-DevOps@lists.edgexfoundry.org to automatically receive all group messages.