How To: Setup Local Git Hook (check for missing JIRA in commit message)

Git Hook Files

  • (original) Git Hook Script: commit-msg
  • (updated - some additional testing might be needed) Git Hook Script: commit-msg
    • Expanded the commit hook to check for some common team/collaboration errors.
      • One when changes are made to the “archive” folder (in our case someone removed the folder completely and checked the set back in breaking things for the rest of the team).
      • Second is when a new script is checked in with a name which already exists in the archive folder

Instructions

The above code can be used for the client side Git hook. This script with ensure that the git commit message has a JIRA ticket listed If the JIRA ticket is missing from the commit, then the commit will fail.

  • The script needs to go in the *_sql repo in the .git/hooks/ directory.
  • The script needs to have execute permission

Maintaining hooks for a team of DBAs can be a little tricky because the .git/hooks directory isn’t cloned with the rest of your project, nor is it under version control. A simple solution to both of these problems is to store your hooks in the actual project directory (above the .git directory). This lets you edit them like any other version-controlled file.

To install the hook, you can either create a symlink to it in .git/hooks (non Windows platforms) , or you can copy and paste it into the .git/hooks directory whenever the hook is updated.


Copyright © Datical 2012-2020 - Proprietary and Confidential