Skip to content

Commit

Permalink
Merge pull request #3 from mikhailsidorov/husky-7-support
Browse files Browse the repository at this point in the history
husky-7-support Add husky 7 version
  • Loading branch information
mikhailsidorov authored Aug 12, 2021
2 parents adb43d5 + 8d92a18 commit 3a4fd03
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 419 deletions.
17 changes: 0 additions & 17 deletions .githooks/prepare-commit-msg

This file was deleted.

31 changes: 31 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

COMMIT_MSG_FILE="${1}"

if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop)
fi

BRANCH_NAME="$(git symbolic-ref --short HEAD)"
BRANCH_NAME="${BRANCH_NAME##*/}"

is_branch_excluded() {
result=0

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}.*$)"
}

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
5 changes: 0 additions & 5 deletions .huskyrc

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Husky prepare-commit-msg example

Example project with prepare-commit-msg hook configured to prepend branch name to commit message automaticaly

## Requirements

* bash

## Run
Expand Down
Loading

0 comments on commit 3a4fd03

Please sign in to comment.