Last active
June 15, 2018 21:45
-
-
Save paulstatezny/f7023f11f5f374e330bc to your computer and use it in GitHub Desktop.
A fish shell function for committing in Git in a "Refs #123 - Commit message." format (Usage: `commit 'Commit message'`)
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
# Prefix commit message with "Refs #[PULL_NUMBER] - " | |
# PULL_NUMBER is derived from the branch name, which is assumed to be in one of the following formats: | |
# something/[PULL_NUMBER]-short-descriptive-name | |
# something/[GROUP_NUMBER]/[PULL_NUMBER]-short-descriptive-name | |
function commit | |
set issue (git rev-parse --abbrev-ref HEAD | cut -d / -f 3 | cut -d - -f 1 | grep "^\d*\$") | |
set message $argv[1] | |
set prefix "Refs #" | |
if [ "$issue" = "" ] | |
set issue (git rev-parse --abbrev-ref HEAD | cut -d / -f 2 | cut -d - -f 1 | grep "^\d*\$") | |
end | |
if [ "$issue" = "" ] | |
set prefix "" | |
else | |
set prefix "Refs #$issue - " | |
end | |
git commit -m "$prefix$message." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples:
Usage:
Branch name:
feature/123-add-profile-pic
commit 'Add initial unit test'
Results in:
Branch name:
group/123/456-add-profile-pic
commit 'Add initial unit test'
Results in: