Last active
May 4, 2017 17:45
-
-
Save subhojit777/086af1c9e0b1f482abd422849f490ca9 to your computer and use it in GitHub Desktop.
Set commit message with current branch name (useful for JIRA mentions)
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 characters
#!/bin/sh | |
# Use case: | |
# --------- | |
# Usually while working on a JIRA ticket, | |
# we would like to put ticket number in commit message. | |
# It becomes tedious to write the ticket number everytime you commit. | |
# Why not let the computer do this task for you? | |
# | |
# Prerequisite: | |
# ------------- | |
# `git config --global core.editor vim` | |
# Or your favourite editor. | |
# | |
# Installation: | |
# ------------- | |
# `vim .git/hooks/prepare-commit_message` | |
# Copy and paste the content of this file. | |
# `chmod +x .git/hooks/prepare-commit_message` | |
# | |
# Usage: | |
# ------ | |
# Create branch with same name as JIRA ticket number. | |
# Say, ticket number is PRJ-576. | |
# You create branch with name as PRJ-576. | |
# When you commit, "PRJ-576: " will be set as message. | |
# You can then add more description to it. | |
ORIG_MSG=$(cat "$1") | |
case "$2" in | |
# Don't do anything when there is already a message. | |
"message"|"template"|"merge"|"commit" ) | |
;; | |
* ) | |
# Get current branch, trim unwanted characters and capitalize. | |
# Just like JIRA ticket numbers. | |
BRANCH=$(git branch | grep '^\*' | sed -e 's/\*.//g' | tr '[a-z]' '[A-Z]') | |
echo "$BRANCH: $ORIG_MSG" > "$1" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment