-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pre-commit
More file actions
44 lines (33 loc) · 989 Bytes
/
git-pre-commit
File metadata and controls
44 lines (33 loc) · 989 Bytes
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
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '(.js)$')
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
echo -e "\nValidating Javascript:\n"
# Check for standard
which node_modules/.bin/standard &> /dev/null
if [[ "$?" == 1 ]]; then
echo -e "\t\033[41mPlease install Standard\033[0m"
exit 1
fi
for FILE in $STAGED_FILES
do
node_modules/.bin/standard --fix "$FILE" > /dev/null
git add "$FILE"
node_modules/.bin/standard "$FILE" --verbose | node_modules/.bin/snazzy
if [[ "$?" == 0 ]]; then
echo -e "\t\033[32mStandard Passed: $FILE\033[0m"
else
echo -e "\t\033[41mStandard Failed: $FILE\033[0m"
PASS=false
fi
done
echo -e "\nJavascript validation completed!\n"
if ! $PASS; then
echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass Standard but do not. Please fix the Standard errors and try again.\n"
exit 1
else
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
exit $?