Hooks are scripts run by Git. Git will run hook scripts based on the situation or the stage of deployment. There are several hooks that are run at different stages of the deployment of code. We are interested in the pre-commit hook—this hook is run before a commit is committed to the repository. There are several good examples for pre-commit hooks available. The Puppet Labs suggested hook runs puppet parser validate
against all the files ending in the .pp
extension. The script can be found at http://projects.puppetlabs.com/projects/1/wiki/puppet_version_control, the website of Puppet Labs. Copy the script from the page into the .git/hooks
directory of your Git repository. The file should be named pre-commit and have the executable permissions set (755 usually).
To test the hook, try committing the following code with an obvious syntax error:
file {'something': path => '/tmp/1', content => 'something' mode => '0644', }
When we add the file and then try to commit...