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
Error out on invalid input for --base (and similar flags) #2129
When using --base to create a PR that should be merged into a specific branch, the request fails with a GraphQL error.
Steps to reproduce the behavior
Create a staging branch, for example: git checkout -b staging/new-feature
Push some work onto it, and push it to origin
Create a branch off of the staging branch: git checkout -b new-feature/part1
Push that branch to origin
Run gh pr create --base staging/new-feature
Expected vs actual behavior
I would expect everything to work as normal, and for the PR to be created with the base branch set as expected.
Instead, there's an error computing the diff between the staging/new-feature and new-feature/part (when computing defaults), and a GraphQL error when submitting. See logs below.
Creating the PR from the web interface works, of course, as does creating the PR with gh pr create (without --base), but the latter of course will need to have the base branch manually set in the web interface after the fact.
I'd hoped this was related to #1926 but I'm on 1.1.0 (as noted above) and still get the same errors.
Thanks for your time!
Logs
Warning: 1 uncommitted change
Creating pull request for new-feature/part1 into staging/new-feature
in my/repo
! warning: could not compute title or body defaults: fatal: ambiguous argument 'origin/staging/new-feature
...new-feature/part1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
git: exit status 128
? Title Part 1
? Body <Received>
? What's next? Submit
pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between staging/new-feature
and new-feature/part1, Base ref must be a branch
@dhleong This does seem like an issue. Did you notice this issue in previous releases or do you think it is a regression from the latest 1.1.0 change?
Do you receive the same error if you try to do gh pr create --base <base branch name>? Where you include the base branch name for the repo in the command. We should be resolving the repo base branch automatically when it is not specified, but maybe that is not working properly.
Did you notice this issue in previous releases or do you think it is a regression from the latest 1.1.0 change?
It was present in 1.0.0 for sure; I don't think I tried to use --base before that.
Do you receive the same error if you try to do gh pr create --base ?
Sorry, I should have been more clear; that is the invocation I'm using and getting this error. I've updated the issue to include the <base branch name> in the invocation in the repro steps for clarity. Not specifying an argument to --base is an error, and not specifying it just tries to create a PR against the main branch; it does not seem to automatically detect the base branch.
Do you think a newline may have snuck into your invocation of gh pr create --base "<branch>"? I.e. instead of passing staging/new-feature as argument, is it possible that you've passed staging/new-feature\n (note the newline character)?
Aha! Great catch! I was indeed generating the <branch> programmatically and passing args as an array, without ensuring any trailing newlines were trimmed. Adding a trim() seems to fix things—thanks!
I suppose it might be worth trimming that flag argument in gh as well, for weird cases like this?
@dhleong It's a good suggestion to somehow try to catch invalid input in gh CLI. Instead of trimming it ourselves (and thus tolerating buggy inputs), I would rather add some kind of input validation to our flag parsing that ensures that most flags error out on extra whitespace. I'm going to rename this issue to reflect this.
changed the title [-]`GraphQL error: Head sha can't be blank` when doing PR create with `--base`[/-][+]Error out on invalid input for `--base` (and similar flags)[/+]on Oct 8, 2020
Activity
samcoe commentedon Oct 8, 2020
@dhleong This does seem like an issue. Did you notice this issue in previous releases or do you think it is a regression from the latest 1.1.0 change?
Do you receive the same error if you try to do
gh pr create --base <base branch name>? Where you include the base branch name for the repo in the command. We should be resolving the repo base branch automatically when it is not specified, but maybe that is not working properly.dhleong commentedon Oct 8, 2020
It was present in 1.0.0 for sure; I don't think I tried to use
--basebefore that.Sorry, I should have been more clear; that is the invocation I'm using and getting this error. I've updated the issue to include the
<base branch name>in the invocation in the repro steps for clarity. Not specifying an argument to--baseis an error, and not specifying it just tries to create a PR against the main branch; it does not seem to automatically detect the base branch.mislav commentedon Oct 8, 2020
@dhleong Thank you for reporting!
Do you think a newline may have snuck into your invocation of
gh pr create --base "<branch>"? I.e. instead of passingstaging/new-featureas argument, is it possible that you've passedstaging/new-feature\n(note the newline character)?dhleong commentedon Oct 8, 2020
Aha! Great catch! I was indeed generating the
<branch>programmatically and passing args as an array, without ensuring any trailing newlines were trimmed. Adding atrim()seems to fix things—thanks!I suppose it might be worth trimming that flag argument in
ghas well, for weird cases like this?mislav commentedon Oct 8, 2020
@dhleong It's a good suggestion to somehow try to catch invalid input in gh CLI. Instead of trimming it ourselves (and thus tolerating buggy inputs), I would rather add some kind of input validation to our flag parsing that ensures that most flags error out on extra whitespace. I'm going to rename this issue to reflect this.
[-]`GraphQL error: Head sha can't be blank` when doing PR create with `--base`[/-][+]Error out on invalid input for `--base` (and similar flags)[/+]dhleong commentedon Oct 8, 2020