Download
36 lines 1.2 KiBBashModified 2026-10-28executable raw
123456789101112131415161718192021222324252627282930313233343536
#!/bin/sh
# fetch.sh GIT_DIR REPOS_FILE: clone or update the bare repositories that
# `make preview` renders. Run from the top of the checkout.
set -eu
git_dir=$1
repos=$2
top=$(pwd)
mkdir -p "$git_dir"
grep -v '^[[:space:]]*\(#\|$\)' "$repos" | while read -r name url section tags desc; do
	case $url in
	*://* | *@*:*) ;;
	*) url=$(cd "$top/$url" && pwd) ;;
	esac
	dir=$git_dir/$name.git
	if [ ! -d "$dir" ]; then
		echo "clone $name <- $url"
		git clone --quiet --bare "$url" "$dir"
		git -C "$dir" config remote.origin.fetch '+refs/heads/*:refs/heads/*'
	else
		echo "fetch $name <- $url"
		git -C "$dir" remote set-url origin "$url"
		git -C "$dir" fetch --quiet --prune --tags origin
	fi
	if [ -n "$desc" ]; then
		printf '%s\n' "$desc" >"$dir/description"
	fi
	# Its section and tags, as repo-render add sets them
	git -C "$dir" config --unset-all repo-render.section || [ $? -eq 5 ]
	git -C "$dir" config --unset-all repo-render.tag || [ $? -eq 5 ]
	[ "$section" = - ] || git -C "$dir" config repo-render.section "$section"
	if [ "$tags" != - ]; then
		printf '%s\n' "$tags" | tr , '\n' | while read -r tag; do
			git -C "$dir" config --add repo-render.tag "$tag"
		done
	fi
done