Skip to content

Instantly share code, notes, and snippets.

@k2wanko
Last active October 27, 2015 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k2wanko/2217a7615b776a29d544 to your computer and use it in GitHub Desktop.
Save k2wanko/2217a7615b776a29d544 to your computer and use it in GitHub Desktop.
prepare-commit-msg
#!/bin/sh
# https://gist.github.com/k2wanko/2217a7615b776a29d544
branch=$(git branch | grep "*" | awk '{print $2}')
# if match , it return number only. if no match, it return branch name.
parse() {
target=$(cat -)
res=$(echo $target | sed -E -e "s/.*((#|issue[s]?[\/-_]?|_|-)([0-9]*)).*/\3/g")
if [ -n "$res" ]; then
echo $res
return 0
fi
res=$(echo $target | sed -E -e "s/^([0-9]*).*/\1/g")
if [ -n "$res" ]; then
echo $res
return 0
fi
res=$(echo $target | sed -E -e "s/^(#|issue[s]?[\/-_]?)([0-9]*)*/\2/g")
if [ -n "$res" ]; then
echo $res
return 0
fi
echo $target
return 1
}
sed="parse"
#echo $branch $(echo $branch | $sed) #dev
#exit 1 #dev
issue=$(echo $branch | $sed)
if [ $branch == $issue ]; then
exit 0
fi
msg=""
if [ "$2" != "message" ]; then
if [ "$(cat $1)" == "$(cat $1 | $sed)" ]; then
echo "refs #$issue\n$(cat $1)" > $1
fi
else
msg=$(cat $1)
if [ "$msg" == "$(echo $msg | $sed )" ]; then
# Add issue num
echo "$(cat $1) #$issue" > $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment