Created
May 7, 2019 06:23
-
-
Save kellpossible/4df68738b7a8c63c627670503ff0b33f to your computer and use it in GitHub Desktop.
A git script to make commits with messages prepended with issue number extracted from the current branch name.
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/sh | |
# A git script to make commits with messages prepended with issue number | |
# extracted from the current branch name. | |
# Config Values | |
ISSUE_TRACKER_URL="http://your-issue-tracker/issues/" | |
EDITOR_COMMAND="vi -c 'set ft=gitcommit'" | |
# Issue Number Extraction | |
BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2) | |
ISSUE_BRANCH_NAME=$(basename $BRANCH_NAME) | |
ISSUE_NUMBER=$(echo $ISSUE_BRANCH_NAME | sed 's/\([0-9]\+\).*$/\1/') | |
# Create temporary file for commit message | |
COMMIT_MSG_FILE=$(mktemp /tmp/git-ac.COMMIT_EDITMSG.XXXXXX) | |
echo " | |
# Committing the changes for issue #$ISSUE_NUMBER | |
# See $ISSUE_TRACKER_URL$ISSUE_NUMBER | |
# | |
# Please enter the commit message for your changes. Lines starting | |
# with '#' will be ignored, and an empty message aborts the commit. | |
# | |
$(git status | sed 's/.*/# &/')" >> $COMMIT_MSG_FILE | |
# Run the text editor to edit the file | |
eval "$EDITOR_COMMAND \$COMMIT_MSG_FILE" | |
# Create the final commit message (with the prepended issue number) | |
COMMIT_MSG_FINAL=$(cat $COMMIT_MSG_FILE | sed '/^#/d') | |
# echo "git commit -m \"#$ISSUE_NUMBER $COMMIT_MSG_FINAL\"" | |
git commit -m "#$ISSUE_NUMBER $COMMIT_MSG_FINAL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this script to your environment
PATH
variable, in order to have it available as a git commandgit ac