GitHooks
https://docs.rc.uab.edu/
Please use the new documentation url https://docs.rc.uab.edu/ for all Research Computing documentation needs.
As a result of this move, we have deprecated use of this wiki for documentation. We are providing read-only access to the content to facilitate migration of bookmarks and to serve as an historical record. All content updates should be made at the new documentation site. The original wiki will not receive further updates.
Thank you,
The Research Computing Team
Git hooks are custom scripts that trigger upon certain git action/command. The ProGit book has explained Git hooks mechanism in detail so I recommend reading it before proceeding with following sections.
Prepare commit message
In most projects a version control system (Git) is integrated with a project management software (trac). It is a good practice to create project management ticket for issue tracking and also reference this ticket number in your version control system's history (commit messages). Also, many developers find it easier to isolate their development work using 'branches'. If you are following such ticket-driven development and want to include ticket-number in every commit message then you may find following commit hook useful. Following example adds reference to a ticket number based on your current working branch.
msg=`git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/# Commit for [galaxy:ticket:\1]/'` sed -i -e "1i $msg" "$1"
The above example works uses GNU sed and hence doesn't work on the Mac OS which uses BSD sed. Following Ruby one-liner example works on both Linux and Mac OS systems.
ruby -i -pe 'puts `git branch`.split(/\n/).select {|e| e =~ /\*.*/}.to_s.sub(/\* /,"# Commit for [galaxy:ticket:").concat("]") if $.==1' "$1"
Modify above one-liners according to your ticket-branch naming convention.