amzn / git-commit-template

Set commit templates for git
Apache License 2.0
18 stars 9 forks source link

Support for husky >=2 #5

Open anshulguleria opened 5 years ago

anshulguleria commented 5 years ago

The current library has been tested with husky 1.x, update the library to support higher versions of husky.

jensbodal commented 2 years ago

You can currently make it work just fine if you do:

HUSKY_GIT_PARAMS="$1" npx --no -- git-commit-template .commit-msg

The prepare-commit-msg script I’m currently using is:

.husky/prepare-commit-msg

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pwd

COMMIT_MSG_FILE=$1  # name of file that contains the commit log message
COMMIT_SOURCE=$2    # message, template, merge, squash, commit
COMMIT_SHA=$3       # exists if amending or reusing a commit

# If there is no commit source then we don't have a template and are just doing `git commit`
# Override any global git templates that are already set
if [ "$COMMIT_SOURCE" == "" -o "$COMMIT_SOURCE" == "template" ]; then
  echo "" > $COMMIT_MSG_FILE
  HUSKY_GIT_PARAMS="$COMMIT_MSG_FILE" npx --no -- git-commit-template .husky/.commit-template
fi

fwiw I also have

.husky/commit-msg

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- devmoji --edit "$1" && \
npx --no -- commitlint --edit "$1"

.husky/pre-commit

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- lint-staged