Last active
December 15, 2015 19:19
-
-
Save KeyboardCowboy/5310979 to your computer and use it in GitHub Desktop.
Automatically add ticket numbers to GIT commit messages using branch descriptions and GIT hooks.
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/bash | |
# | |
# Automatically add ticket numbers to commit messages using branch descriptions. | |
# Place this file in .git/hooks/commit-msg | |
# | |
# Add a description to your branch: | |
# git branch --edit-description [branch-name] | |
# | |
# Mark your ticket numbers anywhere in the description using the following | |
# syntax: | |
# | |
# [#12345678] | |
# | |
# Ex. | |
# This branch is for tickets [#12345678], [#12345679] and | |
# [#23456789]. | |
# Get the branch name | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
# Get the branch description | |
DESC=$(git config branch."$NAME".description) | |
# Grab all the ticket strings out of the description. | |
TICKETS=$(echo $DESC | grep -o '\[\#[0-9]*\]' | tr '\n' ' ') | |
# Prepend the ticket numbers to the commit message | |
echo "$TICKETS"$(cat "$1") > "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment