Skip to content

Instantly share code, notes, and snippets.

@pzi
Last active April 27, 2017 09:30
Show Gist options
  • Save pzi/f909cfd749a44e993261c2a77e39462c to your computer and use it in GitHub Desktop.
Save pzi/f909cfd749a44e993261c2a77e39462c to your computer and use it in GitHub Desktop.
Gets JIRA card number from git branch name and inserts it into the commit message.
function get-jira-card-number {
# Assuming branch names have the following body: XX-1234-Title,
# we are only interested in XX-1234.
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-8 | cut -d"-" -f 1-2
}
function jira-card-number-commit {
local number=`get-jira-card-number`
local message=$1;
if [[ $number && -n $message ]]; then
git commit -m "$number: $message"
else
echo "Missing JIRA card number or message."
fi
}
alias jcm="jira-card-number-commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment