Created
July 16, 2020 14:45
-
-
Save mbensch/5d89759b3ea43b398986d598347cfad4 to your computer and use it in GitHub Desktop.
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 | |
| # git prepare-commit-msg hook for automatically prepending an issue key | |
| # from the start of the current branch name to commit messages. | |
| # check if commit is merge commit or a commit ammend | |
| if [ $2 = "merge" ] || [ $2 = "commit" ]; then | |
| exit | |
| fi | |
| ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"` | |
| if [ $? -ne 0 ]; then | |
| # no issue key in branch, use the default message | |
| exit | |
| fi | |
| # issue key matched from branch prefix, prepend to commit message | |
| TEMP=`mktemp /tmp/commitmsg-XXXXX` | |
| (echo "$ISSUE_KEY: $(cat $1)") > $TEMP | |
| cat $TEMP > $1 | |
| # Hook created by Husky | |
| # Version: 3.0.5 | |
| # At: 2020-5-11 15:06:31 | |
| # See: https://github.com/typicode/husky#readme | |
| # From | |
| # Directory: /Users/mbensch/Bloomfire/bloomfire-app/ui/node_modules/husky | |
| # Homepage: https://github.com/typicode/husky#readme | |
| scriptPath="ui/node_modules/husky/run.js" | |
| hookName=`basename "$0"` | |
| gitParams="$*" | |
| debug() { | |
| if [ "${HUSKY_DEBUG}" = "true" ] || [ "${HUSKY_DEBUG}" = "1" ]; then | |
| echo "husky:debug $1" | |
| fi | |
| } | |
| debug "$hookName hook started" | |
| if [ "${HUSKY_SKIP_HOOKS}" = "true" ] || [ "${HUSKY_SKIP_HOOKS}" = "1" ]; then | |
| debug "HUSKY_SKIP_HOOKS is set to ${HUSKY_SKIP_HOOKS}, skipping hook" | |
| exit 0 | |
| fi | |
| if [ "${HUSKY_USE_YARN}" = "true" ] || [ "${HUSKY_USE_YARN}" = "1" ]; then | |
| debug "calling husky through Yarn" | |
| yarn husky-run $hookName "$gitParams" | |
| else | |
| if ! command -v node >/dev/null 2>&1; then | |
| echo "Info: can't find node in PATH, trying to find a node binary on your system" | |
| fi | |
| if [ -f "$scriptPath" ]; then | |
| # if [ -t 1 ]; then | |
| # exec < /dev/tty | |
| # fi | |
| if [ -f ~/.huskyrc ]; then | |
| debug "source ~/.huskyrc" | |
| . ~/.huskyrc | |
| fi | |
| ui/node_modules/run-node/run-node "$scriptPath" $hookName "$gitParams" | |
| else | |
| echo "Can't find Husky, skipping $hookName hook" | |
| echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment