zeek/testing/external/scripts/sync-commit
Christian Kreibich bf9b1ebbbe Add helpers for syncing commit files with external testsuites
This provides "make sync-repos" to check out all locally available testsuites at
the commits indicated in their commit files, and "make sync-commits" to update
the commit files to the HEADs of the local testsuite repos.

Also adds the commit -> repo sync for the Makefile init target so initialization
always lands on the right version, and removes the corresponding explicit
checkout from the CI repo setup.
2022-06-28 13:20:14 -07:00

30 lines
878 B
Bash
Executable file

#! /usr/bin/env bash
#
# This updates the requested test repo's commit file to the current HEAD commit
# of that repo. If the repo isn't available, this does nothing. If the commit
# file doesn't exist yet, this creates it. It doesn't stage or commit the
# updated commit files.
[[ -z "$1" ]] && {
echo "sync-commit needs a local testsuite repository path as argument"
exit 1
}
repo="$1"
reponame=$(basename $repo)
commitfile=commit-hash.$reponame
[[ ! -d $repo || ! -d $repo/.git ]] && exit 0
commit=$(cd $repo && git log -1 --pretty=format:%H)
[[ -f $commitfile && $(cat $commitfile) == $commit ]] && exit 0
if [[ -n $commit ]]; then
echo "Pinning '$reponame' to $commit"
echo $commit >$commitfile
# If git knows the commit file, show diff:
if git ls-files --error-unmatch $commitfile >/dev/null 2>&1; then
git diff $commitfile
fi
fi