From 345d6d95ff0a6be1a54763e00a00e71a06e33439 Mon Sep 17 00:00:00 2001 From: Mikhail Sidorov <7780462+mikhailsidorov@users.noreply.github.com> Date: Sat, 21 Aug 2021 00:09:02 +0300 Subject: [PATCH] husky-7-support Fix bugs. Update readme --- .husky/prepare-commit-msg | 14 +++++++------- README.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index 07caccd..c19778e 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -4,7 +4,7 @@ COMMIT_MSG_FILE="${1}" if [ -z "$BRANCHES_TO_SKIP" ]; then - BRANCHES_TO_SKIP=(master develop) + BRANCHES_TO_SKIP="master develop" fi BRANCH_NAME="$(git symbolic-ref --short HEAD)" @@ -13,8 +13,8 @@ BRANCH_NAME="${BRANCH_NAME##*/}" is_branch_excluded() { result=0 - for branch in ${BRANCHES_TO_SKIP[@]}; do - if [ $branch = $BRANCH_NAME ]; then + for branch in ${BRANCHES_TO_SKIP}; do + if [ "$branch" = "$BRANCH_NAME" ]; then result=1 fi done @@ -22,10 +22,10 @@ is_branch_excluded() { } is_branch_in_commit_msg() { - echo "$(head -1 $COMMIT_MSG_FILE | grep -c --regexp=^${1}.*$)" + head -1 "$COMMIT_MSG_FILE" | grep -c --regexp=^"${1}".*$ } -if [ -n "$BRANCH_NAME" ] && ! [[ $(is_branch_excluded $BRANCH_NAME) -eq 1 ]] && - ! [[ $(is_branch_in_commit_msg $BRANCH_NAME) -eq 1 ]]; then - sed -i'.bak' -e "1s/^/$BRANCH_NAME /" $COMMIT_MSG_FILE +if [ -n "$BRANCH_NAME" ] && ! [ "$(is_branch_excluded "$BRANCH_NAME")" -eq 1 ] && \ +! [ "$(is_branch_in_commit_msg "$BRANCH_NAME")" -eq 1 ]; then + sed -i'.bak' -e "1s~^~${BRANCH_NAME} ~" "$COMMIT_MSG_FILE" fi diff --git a/README.md b/README.md index 65cd653..3e2629e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Example project with prepare-commit-msg hook configured to prepend branch name t ## Run npm install - git checkout -b issue-123 + git checkout -b fix/issue-123 touch example.txt git add . git commit -m "My new commit"