set -e
if [ ! -t 1 ] && [ -z "$ROCKSDB_FORMAT_HOOK" ]; then
exit 0
fi
FAILED=0
SUSPECT_FILES=$(git ls-files --others --exclude-standard \
| grep -E '\.(cc|cpp|c|h|hpp|java|py|mk|sh)$' \
| grep -v '^third-party/' \
| while IFS= read -r f; do
top_dir="${f%%/*}"
if [ "$top_dir" = "$f" ] || [ -n "$(git ls-files "$top_dir/" | head -1)" ]; then
echo "$f"
fi
done)
if [ -n "$SUSPECT_FILES" ]; then
echo ""
echo "==========================================================="
echo " pre-push: untracked source files in tracked directories."
echo " Push blocked. These may need to be committed, or the"
echo " pushed code could fail to build:"
echo ""
echo "$SUSPECT_FILES" | sed 's/^/ /'
echo ""
echo " Commit them, add to .gitignore, delete, or --no-verify."
echo "==========================================================="
FAILED=1
fi
echo "pre-push: running format check..."
if ! make check-format; then
echo ""
echo "==========================================================="
echo " pre-push: formatting issues detected. Push blocked."
echo " Run 'make format-auto' then amend your commit and retry."
echo "==========================================================="
FAILED=1
else
echo "pre-push: formatting is clean."
fi
exit $FAILED