#!/bin/bash
# Repro for #26560: T3's background status fetch (exact args) loops while the user runs `git pull --ff-only`.
set -u
EXTRA="${1:-}"; N="${2:-200}"
R=$(mktemp -d /tmp/issue-lead-26560-r1/run.XXXX); cd "$R"
git init -q --bare -b main remote.git
git clone -q remote.git seed 2>/dev/null; cd seed; git commit -q --allow-empty -m c0; git push -q origin main; cd ..
git clone -q remote.git work; cd work
( while [ ! -e "$R/stop" ]; do git --git-dir "$PWD/.git" fetch --quiet --no-tags --no-auto-gc $EXTRA -- origin 2>/dev/null; done ) &
BG=$!
fails=0; sample=""
for i in $(seq 1 $N); do
  ( cd ../seed; git commit -q --allow-empty -m c$i; git push -q origin main )
  if ! out=$(git pull -q --ff-only 2>&1); then
    if grep -q "multiple branches" <<<"$out"; then fails=$((fails+1)); sample="$out"; cp .git/FETCH_HEAD "$R/FETCH_HEAD.bad"; fi
  fi
done
touch "$R/stop"; wait $BG
echo "extra='${EXTRA:-<none>}' $(git --version): 'multiple branches' pull failures $fails/$N ${sample}"
[ -e "$R/FETCH_HEAD.bad" ] && sed 's/[0-9a-f]\{40\}/<sha>/g' "$R/FETCH_HEAD.bad"
