From UABgrid Documentation
Revision as of 10:01, 10 January 2012 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.

Personal tools