-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathcheckForOnly.sh
More file actions
executable file
·33 lines (27 loc) · 916 Bytes
/
checkForOnly.sh
File metadata and controls
executable file
·33 lines (27 loc) · 916 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
#!/bin/sh
# =================================================================
# Check that we never commit a .only on a test
# Also check that we never pass a --spec directive in package.json
# =================================================================
stagedFiles=$(git status --porcelain | grep '^M' | awk '{print $2}')
for file in $stagedFiles; do
if [[ $file == "checkForOnly.sh" ]]; then
continue
fi
if [[ $file == "package.json" ]]; then
specDirectiveCount=$(grep "\-\-spec" package.json | wc -l)
if [[ $specDirectiveCount -gt 0 ]]; then
echo "package.json contains a spec directive."
exit 255
else
echo "package.json is OK"
fi
fi
numberOfOnlys=$(grep "\.only" $file | wc -l)
if [[ $numberOfOnlys -gt 0 ]]; then
echo "$file contains .only(s)"
grep -n "\.only" $file --color=auto
exit 255
fi
done
echo "No staged files contain .only"