#!/bin/sh
# Synthetic fixture for pingdotgg/t3code#26390: a superproject with 15 submodules
# behind a fake ssh transport that waits $(cat $F/delay) seconds per connection.
# Start the server with GIT_SSH_COMMAND=$F/bin/slow-ssh, add $F/super as a project,
# and start a thread in "New worktree".
set -e
F=${1:?usage: make-fixture-26390.sh <dir>}
mkdir -p "$F/subs" "$F/bin"
cat > "$F/bin/slow-ssh" <<EOS
#!/bin/sh
for last; do :; done
sleep "\$(cat $F/delay 2>/dev/null || echo 3)"
exec sh -c "\$last"
EOS
chmod +x "$F/bin/slow-ssh"; echo 3 > "$F/delay"
for i in $(seq -w 1 15); do d=$F/subs/sub$i; git init -q -b main "$d"
  for j in $(seq 1 20); do echo "file $j of sub$i" > "$d/f$j.txt"; done
  git -C "$d" add -A; git -C "$d" -c user.name=t -c user.email=t@t commit -qm init; done
git init -q -b main "$F/super"; echo "# super" > "$F/super/README.md"
git -C "$F/super" add -A; git -C "$F/super" -c user.name=t -c user.email=t@t commit -qm init
cd "$F/super"; echo 0 > "$F/delay"
for i in $(seq -w 1 15); do GIT_SSH_COMMAND=$F/bin/slow-ssh git submodule add -q "ssh://fakehost$F/subs/sub$i" "sub$i"; done
git -c user.name=t -c user.email=t@t commit -qm "add 15 submodules"; echo 3 > "$F/delay"
