mirror of
https://github.com/facebook/rocksdb.git
synced 2026-07-07 14:47:40 +08:00
c28b4f0e12
Summary: The previous pre-push hook auto-formatted, committed, and re-pushed on behalf of the user. This was fragile: it's not clear whether the format fix should amend the current commit or create a new one. Adding a commit breaks populating the summary for creating a new PR. Also, the hook's internal re-push would drop flags like --set-upstream from the original command. Replace with a simple check-only approach that blocks the push and tells the user what to fix. Also add a new check for untracked source files (.cc, .h, .py, etc.) in tracked directories (excluding third-party/). These typically indicate files that were forgotten in the commit, which would cause the pushed code to fail to build. Pull Request resolved: https://github.com/facebook/rocksdb/pull/14680 Test Plan: manual Reviewed By: xingbowang Differential Revision: D102855227 Pulled By: pdillinger fbshipit-source-id: 7dc2c4e7a2b2c392bf8da74d7ea43883c8c075a9
62 lines
1.8 KiB
Bash
Executable File
62 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# pre-push hook: block pushing on common mistakes.
|
|
#
|
|
# 1. Checks for untracked source files in tracked directories, which likely
|
|
# need to be committed or removed before the pushed code will build.
|
|
# 2. Runs `make check-format` to verify formatting.
|
|
#
|
|
# Automatically active via `make all` / `make check` (sets core.hooksPath).
|
|
#
|
|
# Skip with:
|
|
# git push --no-verify
|
|
|
|
set -e
|
|
|
|
# Only act when we have a terminal (skip in CI / automated pushes)
|
|
if [ ! -t 1 ] && [ -z "$ROCKSDB_FORMAT_HOOK" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
FAILED=0
|
|
|
|
# --- Check for untracked source files in tracked directories ---
|
|
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
|
|
|
|
# --- Check formatting ---
|
|
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
|