Last active
April 13, 2023 17:26
-
-
Save robatron/01b9a1061e1e8b35d270 to your computer and use it in GitHub Desktop.
Revisions
-
robatron revised this gist
Jan 21, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Automatically Prepend a Jira Issue ID to Git Commit Messages > Use a [git hook](https://git-scm.com/docs/githooks) to match a Jira issue ID from the current branch, and prepend it to every commit message Assuming the current branch contains a Jira issue ID, you can use a git hook script to prepend it to every commit message. 1. Create an empty *commit-msg* git hook file, and make it executable. From your project's root directory: -
robatron revised this gist
Jan 21, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ fi Me too! Here's a one-liner to install the hook above: ```bash if [ -d .git/hooks ]; then HOOKF=.git/hooks/commit-msg && if [ ! -f $HOOKF ]; then TMPF=`date +%s`-ghook && curl -s https://gist.githubusercontent.com/robatron/01b9a1061e1e8b35d270/raw > $TMPF && STARTL=`grep -n "scriptstart" $TMPF | head -1 | cut -d: -f1` && ENDL=`grep -n "scriptend" $TMPF | head -1 | cut -d: -f1` && sed -n `expr \`echo $STARTL\` + 2`,`expr \`echo $ENDL\` - 2`p $TMPF > $HOOKF && chmod 755 $HOOKF; rm $TMPF; else echo "Error: $HOOKF exists"; fi else echo "Error: Not a git repo"; fi ``` ## Enable Hooks Globally -
robatron revised this gist
Jan 21, 2016 . 1 changed file with 0 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +0,0 @@ -
robatron revised this gist
Jan 21, 2016 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,14 @@ fi ``` <!-- scriptend --> ## But I'm Lazy Me too! Here's a one-liner to install the hook above: ```bash if [ -d .git/hooks ]; then HOOKF=.git/hooks/commit-msg && if [ ! -f $HOOKF ]; then TMPF=`date +%s`-ghook && curl -s https://gist.githubusercontent.com/robatron/01b9a1061e1e8b35d270/raw > $TMPF && STARTL=`grep -n "scriptstart" $TMPF | cut -d: -f1` && ENDL=`grep -n "scriptend" $TMPF | cut -d: -f1` && sed -n `expr \`echo $STARTL\` + 2`,`expr \`echo $ENDL\` - 2`p $TMPF > $HOOKF && chmod 755 $HOOKF; rm $TMPF; else echo "Error: $HOOKF exists"; fi else echo "Error: Not a git repo"; fi ``` ## Enable Hooks Globally To enable git hooks for all new git projects, you can use your own git template directory to build out your hooks. See the following article: -
robatron revised this gist
Jan 21, 2016 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,18 @@ if [ -d .git/hooks ]; then HOOKF=.git/hooks/commit-msg if [ -f $HOOKF ]; then TMPF=`date +%s`-ghook curl -s https://gist.githubusercontent.com/robatron/01b9a1061e1e8b35d270/raw > $TMPF STARTL=`grep -n "scriptstart" $TMPF | cut -d: -f1` ENDL=`grep -n "scriptend" $TMPF | cut -d: -f1` sed -n `expr \`echo $STARTL\` + 2`,`expr \`echo $ENDL\` - 2`p $TMPF > $HOOKF chmod 755 $HOOKF rm $TMPF else echo "Error: $HOOKF exists" exit 1 fi else echo "Error: Not a git repo" exit 1 fi -
robatron revised this gist
Jan 21, 2016 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ if [ ! -d .git/hooks ]; then echo "Error: Not a git repo" else HOOKF=.git/hooks/commit-msg if [ -f $HOOKF ]; then echo "Error: $HOOKF exists" else TMPF=`date +%s`-ghook curl -s https://gist.githubusercontent.com/robatron/01b9a1061e1e8b35d270/raw > $TMPF STARTL=`grep -n "scriptstart" $TMPF | cut -d: -f1` ENDL=`grep -n "scriptend" $TMPF | cut -d: -f1` sed -n `expr \`echo $STARTL\` + 2`,`expr \`echo $ENDL\` - 2`p $TMPF > $HOOKF chmod 755 $HOOKF rm $TMPF fi fi -
robatron renamed this gist
Jan 21, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook 1. Save the following script to the newly-created *.git/hooks/commit-msg* file: <!-- scriptstart --> ```bash #!/bin/sh @@ -22,7 +23,7 @@ if [ ! -z "$JIRA_ID" ]; then echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" fi ``` <!-- scriptend --> ## Enable Hooks Globally -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ if [ ! -z "$JIRA_ID" ]; then echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" fi ``` <!-- endscript --> ## Enable Hooks Globally -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ if [ ! -z "$JIRA_ID" ]; then fi ``` ## Enable Hooks Globally To enable git hooks for all new git projects, you can use your own git template directory to build out your hooks. See the following article: -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,12 @@ if [ ! -z "$JIRA_ID" ]; then fi ``` ## Enable Hook Globally To enable git hooks for all new git projects, you can use your own git template directory to build out your hooks. See the following article: https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook ## References - https://git-scm.com/docs/githooks - https://confluence.atlassian.com/display/STASHKB/Integrating+with+custom+JIRA+issue+key -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,11 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. 1. Create an empty *commit-msg* git hook file, and make it executable. From your project's root directory: install -b -m 755 /dev/null .git/hooks/commit-msg 1. Save the following script to the newly-created *.git/hooks/commit-msg* file: ```bash #!/bin/sh -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,9 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. 1. Create a *commit-msg* git hook script, and make it executable. From your project's root directory: install -b -m 755 /dev/null .git/hooks/commit-msg 1. Save the following script to the newly-created *.git/hooks/commit-msg* -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. 1. Create a *commit-msg* git hook script, and make it executable. (From your project's root directory, you can run `install -b -m 755 /dev/null .git/hooks/commit-msg`) 1. Save the following script to the newly-created *.git/hooks/commit-msg* -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,7 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. 1. Create a *commit-msg* git hook script, and make it executable. (From your project's root directory, run `touch .git/hooks/commit-msg && chmod 755 .git/hooks/commit-msg`.) 1. Save the following script to the newly-created *.git/hooks/commit-msg* -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,11 +5,9 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook 1. Create a *commit-msg* git hook script, and make it executable. # From your project's root directory touch .git/hooks/commit-msg chmod 755 .git/hooks/commit-msg 1. Save the following script to the newly-created *.git/hooks/commit-msg* -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Automatically Prepend a Jira Issue ID to Git Commit Messages > Use a [git hook](https://git-scm.com/docs/githooks) to match a Jira issue ID from the current branch, and prepend it to every commit message Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. @@ -30,5 +30,3 @@ fi ## References - https://git-scm.com/docs/githooks - https://confluence.atlassian.com/display/STASHKB/Integrating+with+custom+JIRA+issue+key -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,4 +29,6 @@ fi ## References - https://git-scm.com/docs/githooks - https://confluence.atlassian.com/display/STASHKB/Integrating+with+custom+JIRA+issue+key - hello -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,11 @@ Assuming the current branch contains a Jira issue ID, you can use the a git hook 1. Create a *commit-msg* git hook script, and make it executable. ```bash # From your project's root directory touch .git/hooks/commit-msg chmod 755 .git/hooks/commit-msg ``` 1. Save the following script to the newly-created *.git/hooks/commit-msg* -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,15 @@ # Automatically Prepend a Jira Issue ID to Git Commit Messages > Use a git hook to match a Jira issue ID from the current branch, and prepend it to every commit message Assuming the current branch contains a Jira issue ID, you can use the a git hook script to prepend it to every commit message. 1. Create a *commit-msg* git hook script, and make it executable. # From your project's root directory touch .git/hooks/commit-msg chmod 755 .git/hooks/commit-msg 1. Save the following script to the newly-created *.git/hooks/commit-msg* ```bash #!/bin/sh -
robatron revised this gist
Jan 20, 2016 . 2 changed files with 6 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,9 @@ # Automatically Prepend a Jira Issue ID to Git Commit Messages > Use a git hook to match a Jira issue ID from the current branch, and prepend it to every commit message Assuming the current branch contains a Jira issue ID, you can use the following git hook to prepend it to every commit message: *.git/hooks/commit-msg:* ```bash #!/bin/sh -
robatron revised this gist
Jan 20, 2016 . 2 changed files with 21 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ #!/bin/sh COMMIT_FILE=$1 COMMIT_MSG=$(cat $1) CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+") if [ ! -z "$JIRA_ID" ]; then echo "$JIRA_ID $COMMIT_MSG" > $COMMIT_FILE echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" fi 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,17 @@ # Automatically Prepend a Jira Issue ID to a Git Commit Message ```bash #!/bin/sh COMMIT_FILE=$1 COMMIT_MSG=$(cat $1) CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+") if [ ! -z "$JIRA_ID" ]; then echo "$JIRA_ID $COMMIT_MSG" > $COMMIT_FILE echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" fi ``` ## References -
robatron revised this gist
Jan 20, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,10 @@ # Automatically Prepend a Jira Issue ID to a Git Commit Message ```bash COMMIT_FILE=$1 COMMIT_MSG=`cat $1` JIRA_ID=`git branch --no-color | grep -E "^\*" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+"}` echo "$JIRA_ID $COMMIT_MSG" > $COMMIT_FILE ``` ## References -
robatron created this gist
Jan 20, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Automatically Prepend a Jira Issue ID to a Git Commit Message ```bash git branch --no-color | grep -E "^\*" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+" ``` ## References - https://git-scm.com/docs/githooks - https://confluence.atlassian.com/display/STASHKB/Integrating+with+custom+JIRA+issue+key