#!/bin/bash
# reproduce.sh: builds a throwaway repo in a temp folder where both usual
# answers to "what was main on a date?" go wrong. Touches nothing else.
# From useyappr.com/blog/git-checkout-by-date
set -euo pipefail
cd "$(mktemp -d)" && git init -q -b main && git config user.name test && git config user.email test@example.com
at() { export GIT_AUTHOR_DATE="2026-10-$1 12:00" GIT_COMMITTER_DATE="2026-10-$1 12:00"; }
c() { at "$1"; echo "$2" > "${2%%:*}"; git add .; git commit -qm "$2"; }

c 01 "A: on main"
git switch -qc feature; c 03 "B: made on a branch on the 3rd"
git switch -q main;     c 05 "C: on main"
at 10; git merge -q --no-ff -m "M: B reaches main on the 10th" feature
git switch -qc release; c 12 "D: made on a release branch on the 12th"
git switch -q main; git merge -q --ff-only release   # main jumps to D on the 15th

ask() { git log -1 --format=%s "$(git rev-list -1 "$@" main)"; }
echo "Main on the 4th was A.   --before says:                $(ask --before='2026-10-04 23:59')"
echo "Main on the 13th was M.  --first-parent --before says: $(ask --first-parent --before='2026-10-13 23:59')"
