set -euxo pipefail
temp=$PWD/target/test-vector-sources
rm -rf "$temp"
mkdir -- "$temp"
test_vectors_root=$PWD/test-vectors
test_vectors=$test_vectors_root/dot
rm -rf "$test_vectors_root"
mkdir --parents -- "$test_vectors"
for repo in graphviz graphviz.gitlab.io; do
repo_url=https://gitlab.com/graphviz/$repo
commit=$(git ls-remote "$repo_url" | rg HEAD | awk '{ print $1 }')
test -n "$commit"
tarball_url=https://gitlab.com/graphviz/$repo/-/archive/$commit/$repo-$commit.tar.gz
curl --silent --show-error --location "$tarball_url" \
| tar --extract --verbose --ungzip --touch --directory "$temp"
echo "$commit" > "$test_vectors_root/$repo.commit"
done
for suffix in '*.gv' '*.gv.txt'; do
find "$temp" -name "$suffix" -and -type f -print0 \
| sort --zero-terminated \
| xargs --null cp --backup=numbered --verbose --target-directory="$test_vectors"
done