-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Fix pr create when push.default tracking and no merge ref #10863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BagToad
merged 2 commits into
trunk
from
10862-creating-pr-cannot-determine-remote-branch-name
Apr 24, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
acceptance/testdata/pr/pr-create-push-default-upstream-no-merge-ref-fork.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| skip 'it creates a fork owned by the user running the test' | ||
| skip 'this never worked, but could be fixed if we fixed show-refs' | ||
|
|
||
| # Setup environment variables used for testscript | ||
| env REPO=${SCRIPT_NAME}-${RANDOM_STRING} | ||
| env FORK=${REPO}-fork | ||
|
|
||
| # Use gh as a credential helper | ||
| exec gh auth setup-git | ||
|
|
||
| # Get the current username for the fork owner | ||
| exec gh api user --jq .login | ||
| stdout2env USER | ||
|
|
||
| # Create a repository to act as upstream with a file so it has a default branch | ||
| exec gh repo create ${ORG}/${REPO} --add-readme --private | ||
|
|
||
| # Defer repo cleanup of upstream | ||
| defer gh repo delete --yes ${ORG}/${REPO} | ||
|
|
||
| # Create a user fork of repository. This will be owned by USER. | ||
| exec gh repo fork ${ORG}/${REPO} --fork-name ${FORK} | ||
| sleep 5 | ||
|
|
||
| # Defer repo cleanup of fork | ||
| defer gh repo delete --yes ${USER}/${FORK} | ||
|
|
||
| # Retrieve fork repository information | ||
| exec gh repo view ${USER}/${FORK} --json id --jq '.id' | ||
| stdout2env FORK_ID | ||
|
|
||
| # Clone the repo | ||
| exec gh repo clone ${USER}/${FORK} | ||
| cd ${FORK} | ||
|
|
||
| # Configure push.default so that it should use the merge ref | ||
| exec git config push.default upstream | ||
|
|
||
| # But prepare a branch that doesn't have a tracking merge ref | ||
| exec git checkout -b feature-branch | ||
| exec git commit --allow-empty -m 'Empty Commit' | ||
| exec git push origin feature-branch | ||
|
|
||
| # Create the PR | ||
| exec gh pr create --title 'Feature Title' --body 'Feature Body' | ||
| stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1 | ||
|
|
||
| # Assert that the PR was created with the correct head repository and refs | ||
| exec gh pr view --json headRefName,headRepository,baseRefName,isCrossRepository | ||
| stdout {"baseRefName":"main","headRefName":"feature-branch","headRepository":{"id":"${FORK_ID}","name":"${FORK}"},"isCrossRepository":true} |
33 changes: 33 additions & 0 deletions
33
acceptance/testdata/pr/pr-create-push-default-upstream-no-merge-ref.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| skip 'it creates a fork owned by the user running the test' | ||
|
|
||
| # Setup environment variables used for testscript | ||
| env REPO=${SCRIPT_NAME}-${RANDOM_STRING} | ||
|
|
||
| # Use gh as a credential helper | ||
| exec gh auth setup-git | ||
|
|
||
| # Get the current username for the fork owner | ||
| exec gh api user --jq .login | ||
| stdout2env USER | ||
|
|
||
| # Create a repository to act as upstream with a file so it has a default branch | ||
| exec gh repo create ${ORG}/${REPO} --add-readme --private | ||
|
|
||
| # Defer repo cleanup of upstream | ||
| defer gh repo delete --yes ${ORG}/${REPO} | ||
|
|
||
| # Clone the repo | ||
| exec gh repo clone ${ORG}/${REPO} | ||
| cd ${REPO} | ||
|
|
||
| # Configure push.default so that it should use the merge ref | ||
| exec git config push.default upstream | ||
|
|
||
| # But prepare a branch that doesn't have a tracking merge ref | ||
| exec git checkout -b feature-branch | ||
| exec git commit --allow-empty -m 'Empty Commit' | ||
| exec git push origin feature-branch | ||
|
|
||
| # Create the PR | ||
| exec gh pr create --title 'Feature Title' --body 'Feature Body' | ||
| stdout https://${GH_HOST}/${ORG}/${REPO}/pull/1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an inline comment to clarify that, if the merge ref is empty, the local branch name is intentionally preserved as the remote branch name.