Treat leading or trailing digits in Git branch name as Pit task number

This commit is contained in:
Mike Dvorkin
2011-01-10 23:06:32 -08:00
parent 9d1589b0b7
commit 0709e96baf
2 changed files with 26 additions and 15 deletions

View File

@@ -58,27 +58,29 @@ Pit distribution comes with tools/commit-msg file. Copy this file to
$ cp ~/pit/tools/commit-msg .git/hooks $ cp ~/pit/tools/commit-msg .git/hooks
$ chmod +x .git/hooks/commit-msg $ chmod +x .git/hooks/commit-msg
Create git branch using task number as a branch name. Now on every commit to Create Git branch using Pit task number as leading or trailing digits of the
the branch the hook will prompt you to update task status. The hook appends branch name. Now on every commit to the branch the hook will prompt you to
Pit task number to the commit message, updates Pit task status, and creates update task status. The hook appends Pit task number to the commit message,
task note with the commit massage. For example: updates Pit task status, and creates task note with the commit massage.
$ git checkout -b 2 For example:
Switched to a new branch '2'
$ git checkout -b bugfix-42
Switched to a new branch 'bugfix-42'
$ touch README $ touch README
$ git add . $ git add .
$ git commit -am "Added README file" $ git commit -am "Added README file"
What is the status of task 2? What is the status of task 42?
(I)n progress (I)n progress
(P)ostponed (P)ostponed
(O)pen (O)pen
(D)one (D)one
Enter the status for task 2 [D]: Enter the status for task 42 [D]:
i i
updated task 2: My second task (status: in progress) updated task 42: My second task (status: in progress)
created note 2: Added README file [task 2, status:in progress] (task 2) created note 42: Added README file [task 42, status:in progress] (task 42)
[2 0d930fb] Added README file [task 2, status:in progress] [bugfix-2 0d930fb] Added README file [task 42, status:in progress]
0 files changed, 0 insertions(+), 0 deletions(-) 0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README create mode 100644 README
@@ -189,7 +191,7 @@ A few tips to get you going:
### License ### ### License ###
Copyright (c) 2010 Michael Dvorkin Copyright (c) 2010 Michael Dvorkin
mike[at]dvorkin.net aka mike[at]fatfreecrm.com mike[at]dvorkin.net aka mike[at]fatfreecrm.com aka twitter.com/mid
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

View File

@@ -3,7 +3,9 @@
# Sample Pit integration hook. # Sample Pit integration hook.
# #
# 1. Appends Pit task number to the commit message when you use # 1. Appends Pit task number to the commit message when you use
# task number as your git branch name. # task number as part of your Git branch name. Specifically,
# leading or trailing digits of the branch name are treated
# as Pit task number.
# #
# 2. Lets you specify task status and updates it in Pit accordingly. # 2. Lets you specify task status and updates it in Pit accordingly.
# #
@@ -18,8 +20,15 @@ exec < /dev/tty
ref=$(git symbolic-ref HEAD 2> /dev/null) || return ref=$(git symbolic-ref HEAD 2> /dev/null) || return
branch=${ref#refs/heads/} branch=${ref#refs/heads/}
if [[ $branch =~ ^([0-9]+)$ ]] if [[ $branch =~ ^([0-9]+) ]]; then
then pit_task=${BASH_REMATCH[1]}
else
if [[ $branch =~ ([0-9]+)$ ]]; then
pit_task=${BASH_REMATCH[1]}
fi
fi
if [ -n "$pit_task" ]; then
pit_task=${BASH_REMATCH[1]} pit_task=${BASH_REMATCH[1]}
echo "What is the status of task ${pit_task}?" echo "What is the status of task ${pit_task}?"