diff --git a/resources/git-hooks/prepare-commit-msg b/resources/git-hooks/prepare-commit-msg index 255e0537f5..f5551c4e9d 100755 --- a/resources/git-hooks/prepare-commit-msg +++ b/resources/git-hooks/prepare-commit-msg @@ -1,7 +1,7 @@ #!/bin/bash # -# This prepare-commit-msg hook prepares commit messages to ensure +# This prepare-commit-msg hook prepares commit messages to ensure # that they meet our conventional commit standard. # # Whenever `git` detects an incoming commit, it will trigger this hook. If the message does not @@ -20,7 +20,16 @@ SHA1=$3 # Get the directory where this script lives, i.e. resources/git-hooks HOOK_DIRECTORY="$(dirname "$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")")" -. $HOOK_DIRECTORY/commit-msg-defs +. "$HOOK_DIRECTORY/../build/jq.inc.sh" +. "$HOOK_DIRECTORY/commit-msg-defs" + +# +# Read from our globally shared JSON-formatted scopes and types +# + +scopes=( $("$JQ" -r '[.scopes | paths | reduce .[] as $item (""; if . == "" then $item else . + "/" + $item end)] | join(" ")' < "$HOOK_DIRECTORY/../scopes/scopes.json") ) +types=( $("$JQ" -r '.commitTypes | join(" ")' < "$HOOK_DIRECTORY/../scopes/commit-types.json") ) + # build the regex pattern based on the config file function build_regex() { @@ -83,7 +92,7 @@ function prepend_scope() { postfix="" fi prefix="$TYPE($SCOPE): $EXTRA_WHITESPACE" - + # Reuse any existing message text, wrapping it in our conventional commit formatting before # presenting it to the user for any final edits. echo -e "$prefix$(cat $COMMIT_MSG_FILE)$postfix" > $COMMIT_MSG_FILE @@ -98,7 +107,7 @@ function prepend_scope() { # Step 1 - is the prepared message already in our conventional commits format? $HOOK_DIRECTORY/commit-msg -q $COMMIT_MSG_FILE -isConventional=$? # Grabs the exit code. +isConventional=$? # Grabs the exit code. if [ $isConventional -eq 0 ]; then # If so, great! Don't do a thing!