Git hooks
Environment
Work development environment at this time is primarily Windows, which means I interact with git using powershell and msysgit
Implementation constraints
- Have implemented the hooks as bash scripts, rather than using powershell, as this allows for the deployment of the remote on a linux machine where powershell would not be available
- This also allows us to use a common implementation across all hooks
- Since the scripts are bash scripts we need to ensure the line endings are unix style line endings
commit-msg hook
- Need to copy this content into the .git/hooks/commit-msg file on all the developer’s workstations
- This sample commit-msg hook will check that local commits (excluding merge commits) have a commit message that starts with a very specific pattern, here it checks that every commit’s commit message starts with a feature identifier
- This check will apply to commits on all branches, so it may be too restrictive for experimental branches, could alter to only apply to the master branch
update hook
- Need to copy this content into the remote repository /hooks/update file
- This sample update hook which should be deployed within the bare remote repository will check that pushes commits (excluding merge commits) have a commit message that starts with a very specific pattern, here it checks that every commit’s commit message starts with a feature identifier
- This check will be applied to all branches, not just the master branch, so if pushing experimental branches this may be a bit restrictive