Skip to content

Commit

Permalink
Don't run linter when deleting a remote branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Feb 2, 2024
1 parent 181b102 commit 112cd52
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

. "$(dirname -- "$0")/_/husky.sh"

echo "*** Checking for lint violations in changed files ***************"
echo
# If the push refs start with (delete), then we're deleting a branch, so skip the pre-push hook
# Source: <https://github.com/typicode/husky/issues/169#issuecomment-1719263454>
stdin=$(cat -)
if echo "$stdin" | grep -q "^(delete)"; then
exit 0
fi

files_to_check=$(git diff --cached "$(git merge-base main HEAD)" --name-only --diff-filter=d)
if [[ -n $files_to_check ]]; then
echo "*** Checking for lint violations in changed files ***************"
echo

yarn prettier --check --ignore-unknown $(git diff --cached "$(git merge-base main HEAD)" --name-only --diff-filter=d) || exit $?
yarn prettier --check --ignore-unknown $files_to_check || exit $?
fi

echo
echo "*** Auditing dependencies ***************"
Expand Down

0 comments on commit 112cd52

Please sign in to comment.