#!/usr/bin/env bash
set -euo pipefail
: "${AZURE_DEVOPS_EXT_PAT:?Export the test token}"
: "${AZURE_DEVOPS_TEST_ORG:?Export the test organization URL}"
: "${AZURE_DEVOPS_TEST_PROJECT:?Export the test project}"
root="$(dirname "$0")"
url="$(jq -r .remoteUrl "$root/repo.json")"
git init --initial-branch=main "$root/merge-demo"
cd "$root/merge-demo"
git config user.name "Merge proof"
git config user.email "proof@example.invalid"
printf 'Merge method proof\n' > README.md
git add README.md
git commit -m 'Initial fixture'
git remote add origin "$url"
git -c credential.helper='!f() { echo username=pat; echo "password=$AZURE_DEVOPS_EXT_PAT"; }; f' push origin main
git checkout -b proof-change
printf 'A change for merge preview\n' >> README.md
git commit -am 'Fixture change'
git -c credential.helper='!f() { echo username=pat; echo "password=$AZURE_DEVOPS_EXT_PAT"; }; f' push origin proof-change
az repos pr create --organization "$AZURE_DEVOPS_TEST_ORG" --project "$AZURE_DEVOPS_TEST_PROJECT" --repository merge-default-proof-29857 --source-branch proof-change --target-branch main --title 'Project merge method proof' --description 'Synthetic fixture; leave unmerged.' -o json > "$root/pr.json"
