Using git hooks to avoid mistakes
Currently, I have a series of chef cookbooks and a munki repo that I consistently push up to Github. I have found using a pre-commit git hook for when I commit being helpful to avoid pushing code up that isn’t quite right.
An example of a typical chef cookbook git pre-commit hook:
Since I am on MacOS, I am going to destroy all .DS_Store files.
Then in all of my cookbooks, I have a Rakefile, and chef exec rake style
runs rubocop and foodcritic, so that I am not commiting blatant errors in either Ruby or Chef.
An example of a munki git pre-commit hook:
Again, destroy all .DS_Store files if they exist, then using plutil I do a lint check of all the property lists(or plists) in the repository. A malformed plist is going to make munki fail, and maybe I forgot to add a closing bracket or something, better to catch that before putting this code into production, or testing.