Skip to content

Commit

Permalink
Merge pull request #4 from mikhailsidorov/husky-7-support
Browse files Browse the repository at this point in the history
husky-7-support Fix bugs. Update readme
  • Loading branch information
mikhailsidorov authored Aug 20, 2021
2 parents 3a4fd03 + 345d6d9 commit d5f214c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -13,19 +13,19 @@ 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
echo $result
}

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d5f214c

Please sign in to comment.