#!/bin/sh # clone-at : that one commit of a repository, without its history, checked out and checked against # the pin. From Beijing a connection to github.com times out about every other time (12-02: two of three, each after # 135 s), so a fetch that stalls is cut off, and each is tried up to ten times: through $GITHUB_MIRROR first where one # is set (a proxy in front of github.com), then from github.com itself, in turn. Whoever serves it, git names a commit # by the hash of its content, and the hash is the pin. `origin` stays the repository's own address, as Lake expects of # a package. set -eu url=$1 dir=$2 commit=$3 mirror=$(printf %s "$url" | sed "s#^https://github.com#${GITHUB_MIRROR:-https://github.com}#") n=0 until rm -rf "$dir" && git init -q "$dir" && git -C "$dir" remote add origin "$url" \ && { if [ $((n % 2)) = 0 ]; then from=$mirror; else from=$url; fi; } \ && timeout 300 git -C "$dir" -c http.lowSpeedLimit=1000 -c http.lowSpeedTime=30 fetch -q --depth 1 "$from" "$commit"; do n=$((n + 1)) [ "$n" -lt 10 ] sleep 3 done git -C "$dir" -c advice.detachedHead=false checkout -q FETCH_HEAD test "$(git -C "$dir" rev-parse HEAD)" = "$commit"