# Use gh as a credential helper
exec gh auth setup-git

# Create a repository with a file so it has a default branch
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private

# Defer repo cleanup
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING

# Clone the repo
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
cd $SCRIPT_NAME-$RANDOM_STRING
exec git config user.email "test@example.com"
exec git config user.name "Test User"

# Add a file with searchable content
mv ../searchable.txt searchable.txt
exec git add .
exec git commit -m 'Add searchable content'
exec git push origin main

# Wait for indexing
sleep 2

# Search for the unique content within this repo (use --json since non-TTY lacks text_matches)
exec gh search code 'UniqueSearchablePhrase' -R $ORG/$SCRIPT_NAME-$RANDOM_STRING --json path --jq '.[].path'
stdout 'searchable.txt'

-- searchable.txt --
This file contains UniqueSearchablePhrase for acceptance testing
