#!/bin/sh
#
# A pre-push hook that makes sure all testing/external changes
# have been pushed already. If not, it will abort. Note that
# it will only check for unpushed commits, not for uncommitted
# changes.
#
# To install this, copy it into you Zeek tree's .git/hooks/pre-push.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If this script exits with a non-zero status nothing will be pushed.

test -d testing/external || exit 0

cd testing/external

base=$(pwd)
abort=0

for repo in $(./scripts/find-git-repos); do
    cd ${base}/${repo} &&
        git rev-list @{u}.. | grep -q . &&
        echo "ERROR: testing/external/$(basename $repo) has commits that are not pushed." &&
        abort=1
done

exit ${abort}
