Describe the bug
The following Acceptance test demonstrates the issue:
# Set up env vars
env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
# 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}/${REPO} --add-readme --private
# Defer upstream cleanup
defer gh repo delete --yes ${ORG}/${REPO}
# Create a fork
exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${REPO}-fork
# Defer fork cleanup
defer gh repo delete --yes ${ORG}/${REPO}-fork
# Clone both repos
exec gh repo clone ${ORG}/${REPO}
exec gh repo clone ${ORG}/${REPO}-fork
# Prepare a branch to PR in the fork itself
cd ${REPO}-fork
exec git checkout -b feature-branch
exec git commit --allow-empty -m 'Empty Commit'
exec git push -u origin feature-branch
# Create the PR inside the fork
exec gh repo set-default ${ORG}/${REPO}-fork
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout2env PR_URL
# Checkout the PR by full URL in the upstream repo
cd ${WORK}/${REPO}
exec gh pr checkout ${PR_URL}
stderr 'Switched to branch ''feature-branch'''
It fails at this point:
[git -c credential.helper= -c credential.helper=!"/var/folders/45/sdnm1hp10nj1s9q57dp3bc5h0000gn/T/testscript-main1265888467/bin/gh" auth git-credential fetch origin +refs/heads/feature-branch:refs/remotes/origin/feature-branch --no-tags]
fatal: couldn't find remote ref refs/heads/feature-branch
failed to run git: exit status 128
Affected version
Regressed after #9868
Notes
The issue is that the base repo of the PR may not be the same as the base repo of the current working directory. See in this diff, that the BaseRepo from the PRFinder is ignored, and instead the return of opts.BaseRepo is used:
https://github.com/cli/cli/pull/9868/files#diff-b5ec653aa1e550e4c5f2df8ad7fc22dfbaedf71270cb5a328d7327f2a8093d66R96-R294
Describe the bug
The following Acceptance test demonstrates the issue:
It fails at this point:
Affected version
Regressed after #9868
Notes
The issue is that the
baserepo of the PR may not be the same as thebaserepo of the current working directory. See in this diff, that theBaseRepofrom thePRFinderis ignored, and instead the return ofopts.BaseRepois used:https://github.com/cli/cli/pull/9868/files#diff-b5ec653aa1e550e4c5f2df8ad7fc22dfbaedf71270cb5a328d7327f2a8093d66R96-R294