Prevent Git Commits with Unformatted Go Code
October 7, 2023
#100DaysToOffload
#Git
#Go
#Tidbit
Git has this great feature that I think is well-known but under-used. I am talking about Git hooks.
With Git hooks, you can run scripts during different Git actions.
Like this one:
|
|
This script will take a list of all the staged Go files. It will then run gofmt
to determine if these Go files are not formatted.
If you use it as a part of the pre-commit hook of your Git repository in your Go project, it will prevent commits with unformatted Go files.
To use it as the pre-commit hook, save it as pre-commit
inside the .git/hooks/
directory.
This post is 59th of my #100DaysToOffload challenge. Want to get involved? Find out more at 100daystooffload.com.
comments powered by Disqus
Similar Blog Posts
September 30, 2023
#100DaysToOffload
#Go
#Tidbit