Skip to content

Error out on invalid input for --base (and similar flags) #2129

Open

Description

@dhleong

Describe the bug

gh version 1.1.0 (2020-10-06)

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

  1. Create a staging branch, for example: git checkout -b staging/new-feature
  2. Push some work onto it, and push it to origin
  3. Create a branch off of the staging branch: git checkout -b new-feature/part1
  4. Push that branch to origin
  5. 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

Activity

  1. added
    bug
    on Oct 7, 2020
  2. added
    more-info-needed
    on Oct 8, 2020
  3. samcoe commented on Oct 8, 2020

    @samcoe
    Contributor

    @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.

  4. added
    priority-2
    on Oct 8, 2020
  5. dhleong commented on Oct 8, 2020

    @dhleong
    ContributorAuthor

    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.

  6. mislav commented on Oct 8, 2020

    @mislav
    Contributor

    @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 passing staging/new-feature as argument, is it possible that you've passed staging/new-feature\n (note the newline character)?

  7. dhleong commented on Oct 8, 2020

    @dhleong
    ContributorAuthor

    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?

  8. mislav commented on Oct 8, 2020

    @mislav
    Contributor

    @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.

  9. 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
  10. added
    priority-3
    and removed
    more-info-needed
    priority-2
    on Oct 8, 2020
  11. dhleong commented on Oct 8, 2020

    @dhleong
    ContributorAuthor
  12. added
    gh-pr
    on Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-prpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions