-
-
Save plu/4124580 to your computer and use it in GitHub Desktop.
Pre-commit hook to check for NSLog statements in Objective-C repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# name this .git/hooks/pre-commit | |
# chmod +x .git/hooks/pre-commit | |
# enjoy | |
IFS=$'\n' | |
if git-rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
# so it will work on empty repos | |
against=emptyreposhavenocommits | |
fi | |
EC=0 | |
for FILEPATH in $(git diff-index --name-status $against -- | cut -c3-); do | |
FILE=$(basename "$FILEPATH") | |
if [[ "${FILE:0:1}" == "_" ]]; then | |
continue | |
fi | |
if [[ ! -f "$FILEPATH" ]]; then | |
continue | |
fi | |
if [[ "${FILEPATH:0:4}" == "Pods" ]]; then | |
continue | |
fi | |
if grep -q 'NSLog' "$FILEPATH"; then | |
echo "\033[1;31mERROR: $FILEPATH has an NSLog on following line(s):\033[m" | |
grep -n NSLog "$FILEPATH" | |
let EC="$EC+1" | |
fi | |
done | |
if [ $EC -gt 0 ]; then | |
echo "\033[1mTip: Use git commit --no-verify to ignore this\033[0m" | |
fi | |
exit $EC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment