Skip to content

Instantly share code, notes, and snippets.

@makotoshimazu
Last active August 29, 2015 14:12
Show Gist options
  • Save makotoshimazu/066ca3e0badb3d161dc4 to your computer and use it in GitHub Desktop.
Save makotoshimazu/066ca3e0badb3d161dc4 to your computer and use it in GitHub Desktop.
Redmineでチケット番号を入れるのが面倒なのでつくった
#!/bin/bash
#
# git-feature
#
# Author: Makoto Shimazu <[email protected]>
# URL: https://amiq11.tumblr.com
# License: MIT License
# Created: 2015-01-06
#
function error_exit() {
echo "ERROR: $1" 1>&2
exit 1
}
[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] && error_exit "Current directory is not controlled by git"
case "$1" in
"fix")
shift
current_branch=$(git status | head -n1 | cut -f 3 -d ' ')
ticket_no=$(basename "$current_branch"| grep -E '[1-9][0-9]*')
[ "$ticket_no" == "" ] && error_exit "Current branch (${current_branch}) is not feature branch"
args=""
while [ $# -gt 0 ]
do
args="${args} '$1'"
if [[ "$1" =~ ^-.*m$ ]]; then
shift
[ $# == 0 ] && error_exit "'-m' option must have one following argument"
args="${args} '$1 fixes'"
fi
shift
done
eval exec git feature commit $args
;;
"commit")
shift
current_branch=$(git status | head -n1 | cut -f 3 -d ' ')
ticket_no=$(basename "$current_branch"| grep -E '[1-9][0-9]*')
[ "$ticket_no" == "" ] && error_exit "Current branch (${current_branch}) is not feature branch"
args=""
while [ $# -gt 0 ]
do
args="${args} '$1'"
if [[ "$1" =~ ^-.*m$ ]]; then
shift
[ $# == 0 ] && error_exit "'-m' option must have one following argument"
args="${args} '$1 #${ticket_no}'"
fi
shift
done
eval exec git commit $args
;;
"push")
shift
git push $@
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment