You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
git pr create --dry-run works with remote branch but actual command does not #9201
I have a branch that I pushed and deleted locally. I can reference it using origin/branch-name. gh pr create --dry-run works with origin/branch-name reference, but same invocation without --dry-run does not.
$ gh --version
gh version 2.50.0 (2024-05-29)
https://github.com/cli/cli/releases/tag/v2.50.0
master$ gh pr create --base master --head origin/findepi/sample-branch --fill --dry-run
Dry Running pull request for origin/findepi/sample-branch into master in xxx/xxx
Would have created a Pull Request with:
Title: My sample commit
Draft: false
Base: master
Head: origin/findepi/sample-branch
MaintainerCanModify: true
Body:
My commit description.
master$ gh pr create --base master --head origin/findepi/sample-branch --fill
Creating pull request for origin/findepi/sample-branch into master in xxx/xxx
pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between master and origin/findepi/sample-branch, Head ref must be a branch (createPullRequest)
Steps to reproduce the behavior
Create a branch, push it, and delete locally
Use gh pr create --dry-run to dry-run creation of a PR from that branch
Use gh pr create to finalize creation of a PR from that branch
Expected vs actual behavior
If --dry-run works, the call without --dry-run should work too.
If origin/... references are not accepted, --dry-run should not accept them either.
Thank you for opening this issue, @findepi, and apologies for any frustration this might have caused! 🙇
If --dry-run works, the call without --dry-run should work too.
If origin/... references are not accepted, --dry-run should not accept them either.
I generally agree with the overall spirit of what you're saying — "If this won't work, then tell me about it during --dry-run — so let's put a fine point on exactly what should happen here.
Let's dig into the code
This is the bulk of code involved in creating PRs:
gh passes your head branch argument, which is a local reference to a remote reference, straight to the GitHub API when creating the PR causes this to error
NewCreateContext logic seems like it can be enhanced to detect if --base or --head are remote references which don't make sense in this context
Activity
Talkinghawk commentedon Jun 17, 2024
andyfeller commentedon Aug 1, 2024
Thank you for opening this issue, @findepi, and apologies for any frustration this might have caused! 🙇
I generally agree with the overall spirit of what you're saying — "If this won't work, then tell me about it during
--dry-run— so let's put a fine point on exactly what should happen here.Let's dig into the code
This is the bulk of code involved in creating PRs:
cli/pkg/cmd/pr/create/create.go
Lines 243 to 324 in b05bddc
cli/pkg/cmd/pr/create/create.go
Lines 707 to 749 in b05bddc
Digging a little bit deeper, I think all of the logic for handling user arguments and flags happens when the context for creating the PR here:
cli/pkg/cmd/pr/create/create.go
Lines 538 to 692 in b05bddc
It is here we see validation for a variety of cases including some checking around the
--baseand--headarguments:cli/pkg/cmd/pr/create/create.go
Lines 666 to 677 in b05bddc
Thoughts
ghpasses your head branch argument, which is a local reference to a remote reference, straight to the GitHub API when creating the PR causes this to errorNewCreateContextlogic seems like it can be enhanced to detect if--baseor--headare remote references which don't make sense in this context