-
-
Save josephdpurcell/aee59ab2804ca50e6ee9 to your computer and use it in GitHub Desktop.
Make Mac friendly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# An example hook script to prepare the commit log message. | |
# Called by "git commit" with the name of the file that has the | |
# commit message, followed by the description of the commit | |
# message's source. The hook's purpose is to edit the commit | |
# message file. If the hook fails with a non-zero status, | |
# the commit is aborted. | |
# | |
# To enable this hook, rename this file to "prepare-commit-msg" and | |
# place it in .git/hooks. | |
# | |
# To enable this for all git projects uses the global configuration | |
# 'init.templatedir'. Create a directory for git templates and a | |
# subdirectory for hooks. | |
# > mkdir -p ~/.git_template/hooks | |
# Use the following command to configure this as your git templates | |
# directory. | |
# > git config --global init.templatedir '~/.git_template' | |
# | |
# Now when you init a new git repo, the hook directory along with | |
# any hooks will automatically be placed in the new project git | |
# repo. | |
# | |
# You can also run 'git init' on an existing repo to have the | |
# reinitialized with the latest templates. | |
# | |
# Exit status of non zero will lead to a failed commit. | |
# Get the name of the branch in the current working tree. | |
NAME=$(git symbolic-ref -q --short HEAD) | |
# Check the branch name for a 5 to 7 digit number (an issue number). | |
if [ `uname -s` = 'Darwin' ] | |
then | |
ISSUE_NUMBER=`expr "$NAME" : '\([0-9]*\)'` | |
else | |
ISSUE_NUMBER=`expr match "$NAME" '\([0-9]\{5,7\}\)'` | |
fi | |
# If branch contains a match for an issue number prepend the commit | |
# message with 'Ref <issue_number> <commit message>. | |
if [ -n "$ISSUE_NUMBER" ] | |
then | |
OLD_IFS=$IFS | |
IFS='' | |
echo "Ref $ISSUE_NUMBER\n"$(cat "$1") > "$1" | |
IFS=$OLD_IFS | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment