#!/bin/sh # Turn a WORKING TREE into a bare repo the lab server can hand out. # # `git clone` of a checkout only ever produces committed refs, so testing a # change used to mean pushing it first -- which is backwards, and is the reason # every bug in this repo was found by a human on a real machine instead of by # a test. Copying the tree and committing it into a throwaway repo means the # code under test is whatever is on disk right now, staged or not. # # usage: snapshot.sh set -eu src=$1; root=$2; name=$3 work=$(mktemp -d) trap 'rm -rf "$work"' EXIT # --delete is pointless into a fresh mktemp dir, but it documents intent if # this is ever pointed at a reused path. tar -C "$src" --exclude=.git -cf - . | tar -C "$work" -xf - git -C "$work" init -q -b main git -C "$work" add -A git -C "$work" \ -c user.email=lab@example.invalid -c user.name=lab \ commit -qm "working-tree snapshot of $name" rm -rf "$root/$name.git" mkdir -p "$root" git clone -q --bare "$work" "$root/$name.git" git -C "$root/$name.git" update-server-info printf '%s\n' "$root/$name.git"