Created
October 31, 2012 18:39
-
-
Save tomkersten/3988986 to your computer and use it in GitHub Desktop.
Auto-associated ticket number with commit based on branch name
This file contains 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
# If you have a branch named "tSOME_NUMBER" (eg: 't332'), this will open that | |
# ticket in a web browser for review. | |
# | |
# eg: | |
# $ git co t332 | |
# $ review | |
# ...browser opens to ticket #332 page | |
# | |
# replace SOME_URL with the URL up-to the ticket number in your issue/ticket-management system | |
# eg: "https://github.com/USER_ID/PROJECT_NAME/issues/" | |
# | |
alias review='git branch -a |grep ^\* |awk '\''{print $2}'\''|sed -ne '\''s/^t//p'\''|awk '\''{print "https://SOME_URL/"$1}'\''|xargs open' | |
This file contains 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 | |
# | |
# Overview | |
# -------- | |
# | |
# If your current branch name is "t" followed by some number (eg: 't332'), this | |
# will insert a "[refs: #$(TICKET_NUMBER)]" (eg: "[refs: #332]") at the bottom | |
# of your commit message. | |
# | |
# -------------------------------------- | |
# Original README content below here.... | |
# 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". | |
BRANCH_NAME=`git symbolic-ref HEAD| cut -d/ -f 3|grep ^t[0-9]*$` | |
if [ $? == "0" ]; then | |
TICKET_NUMBER=`echo $BRANCH_NAME | sed -ne 's/^t//p'` | |
exec 3<> $1 && awk -v TEXT="\n\n[refs: #$TICKET_NUMBER]" 'BEGIN {print TEXT}{print}' $1 >&3 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment