-
Notifications
You must be signed in to change notification settings - Fork 1
/
commit-msg
64 lines (48 loc) · 1.54 KB
/
commit-msg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
export TERM=xterm-256color
GIT_PROJECT_LOCATION=$(git rev-parse --show-toplevel)
GIT_PROJECT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_PROJECT_LATEST_REVISION=$(git rev-list -n 1 HEAD)
ESLINT_FILE_PATH=$GIT_PROJECT_LOCATION"/.eslintrc"
echo ""
echo "# Running commit-msg git hook"
echo "# ------------------------------------------------------"
echo "# Location: $GIT_PROJECT_LOCATION"
echo "# Branch: $GIT_PROJECT_BRANCH"
echo "# Last revision: $GIT_PROJECT_LATEST_REVISION"
# assume success
ALLOW_COMMIT=1
# for every new file, copied and/or modified
# whose extension matches .js
# run eslint whitelistingg globals (require and export)
LINTABLE=$(git diff --name-only --staged --diff-filter ARCM '*.js')
if [ -z "$LINTABLE" ]; then
echo "# No js modified files. Skip lint verification"
echo "# Proceeding to commit your changes"
echo "# Good Bye"
exit 0
fi;
echo ""
echo "...please stand by eslint had started to verify staged changes..."
echo ""
for LINTME in $LINTABLE;
do
LINTCMD=$(eslint --global require --global exports:true --quiet $LINTME 2>&1)
if [ $? -ne 0 ]; then
echo "$LINTCMD" && ALLOW_COMMIT=0;
fi;
done;
echo ""
if [ $ALLOW_COMMIT -eq 1 ]; then
echo "# Code looks OK"
echo "# Commiting now..."
echo "# Bye"
exit 0
fi;
echo "# Sorry!"
echo "# Your Commit Had Been Rejected"
echo "# Code you are trying to commit did not pass code style verification"
echo "# See $ESLINT_FILE_PATH for guidelines"
echo "# Apply fix(es) and commit again"
echo "# Good bye..."
exit 1