Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][IMP] husky: allow use of pre-commit hook for windows #1519

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 28 additions & 14 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Husky Env Variables :
# HUSKY_PRE_COMMIT : if set to 0, disable pre-commit hook
# HUSKY_INPUT_ENV: if set to 0, disable the possibility of user input for the hook

npx="npx"

# For Windows
if [ "$OSTYPE" = "msys" ]; then
export PATH="/usr/bin:/usr/local/bin:$PATH"
npx="npx.cmd"
fi
. "$(dirname "$0")/_/husky.sh"

if [ "$HUSKY_PRE_COMMIT" != 0 ]; then
npx lint-staged
# ativate user inputs
exec < /dev/tty
$npx lint-staged

consoleregexp='console\.|debugger'

# CHECK
if test $(git diff --cached | grep -nE $consoleregexp | wc -l) != 0
then
exec git diff --cached --color | grep -nE $consoleregexp -A 2 -B 2
read -p "There are some occurrences of forbidden patterns at your modification. Are you sure want to continue? (y/n)" yn
echo $yn | grep ^[Yy]$
if [ $? -eq 0 ]
then
exit 0; #THE USER WANTS TO CONTINUE
then
if [ "$HUSKY_INPUT_ENV" != 0 ] && [ "$OSTYPE" != "msys" ]; then
# activate user inputs
exec < /dev/tty
exec git diff --cached --color | grep -nE $consoleregexp -A 2 -B 2
read -p "There are some occurrences of forbidden patterns at your modification. Are you sure want to continue? (y/n)" yn
echo $yn | grep ^[Yy]$
if [ $? -eq 0 ]
then
exit 0; #THE USER WANTS TO CONTINUE
else
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK
fi
else
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK
echo -e "\033[1;31mWARNING: Some occurences of forbidden patterns were detected \033[0m"
exec git diff --cached --color | grep -nE $consoleregexp -A 2 -B 2
fi
fi
fi
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.husky/