about summary refs log tree commit diff
path: root/src/etc/pre-push.sh
blob: 33ed2f0e406b14421e8ad71af62b7a5805d6d116 (plain)
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
#!/usr/bin/env bash
#
# Call `tidy` before git push
# Copy this script to .git/hooks to activate,
# and remove it from .git/hooks to deactivate.
#

set -Euo pipefail

# Check if the push is doing anything other than deleting remote branches
SKIP=true
while read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA; do
    if [[ "$LOCAL_REF" != "(delete)" || \
          "$LOCAL_SHA" != "0000000000000000000000000000000000000000" ]]; then
        SKIP=false
    fi
done

if $SKIP; then
    echo "Skipping tidy check for branch deletion"
    exit 0
fi

ROOT_DIR="$(git rev-parse --show-toplevel)"

echo "Running pre-push script $ROOT_DIR/x test tidy"

cd "$ROOT_DIR"
# The env var is necessary for printing diffs in py (fmt/lint) and cpp.
TIDY_PRINT_DIFF=1 ./x test tidy \
    --set build.locked-deps=true \
    --extra-checks auto:py,auto:cpp,auto:js
if [ $? -ne 0 ]; then
    echo "You may use \`git push --no-verify\` to skip this check."
    exit 1
fi