Skip to content

PR Create - GraphQL error due to wrong head branch detected #1820

Closed

Description

@jharshman

Describe the bug

When trying to create a Pull Request through gh pr create, I run into the following error:

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch
gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0

Steps to reproduce the behavior

  1. Fork a repo
  2. Clone and set origin and upstream
  3. Create a branch and commit some changes
  4. Run the following: gh pr create --fill

Expected vs actual behavior

I would have expected to see the PR created. Instead it results in the following error message.

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch

Logs

$ DEBUG=api gh pr create --fill                                                                     
[git remote -v]                                                  
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2020-09-18 16:23:58.899000113 -0600 MDT m=+0.032056143
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\tquery RepositoryInfo($owner: String!, $name: String!) {\n\t\trepository(owner: $owner, name: $name) {\n\t\t\tid\n\t\t\tname\n\t\t\towner { login }\n\t\t\thasIssuesEnabled\n\t\t\tdescription\n\t\t\tviewerPermission\n\t\t\tdefaultBranchRef {\n\t\t\t\tname\n\t\t\t}\n\t\t}\n\t}",
    "variables": {
        "name": "bitly",
        "owner": "bitly"
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id: 
< X-Oauth-Client-Id: 
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4951
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 49
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "repository": {
            "id": "MDEwOlJlcG9zaXRvcnkxNzYxMDE4",
            "name": "bitly",
            "owner": {
                "login": "bitly"
            },
            "hasIssuesEnabled": true,
            "description": "Bitly core repository",
            "viewerPermission": "WRITE",
            "defaultBranchRef": {
                "name": "master"
            }
        }
    }
}
* Request took 512.90788ms
[git symbolic-ref --quiet --short HEAD]
[git status --porcelain]
[git config --get-regexp ^branch\.conftest-app-metrics\.(remote|merge)$]
[git show-ref --verify -- HEAD refs/remotes/jharshman/conftest-app-metrics refs/remotes/origin/conftest-app-metrics refs/remotes/bitly/conftest-app-metrics refs/remotes/jharshman/conftest-app-metrics refs/remotes/mrwoof/conftest-app-metrics]
[git -c log.ShowSignature=false log --pretty=format:%H,%s --cherry origin/master...conftest-app-metrics]
* Request at 2020-09-18 16:23:59.506737366 -0600 MDT m=+0.639793409
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\tquery PullRequestForBranch($owner: String!, $repo: String!, $headRefName: String!) {\n\t\trepository(owner: $owner, name: $repo) {\n\t\t\tpullRequests(headRefName: $headRefName, states: OPEN, first: 30) {\n\t\t\t\tnodes {\n\t\t\t\t\tid\n\t\t\t\t\tnumber\n\t\t\t\t\ttitle\n\t\t\t\t\tstate\n\t\t\t\t\tbody\n\t\t\t\t\tmergeable\n\t\t\t\t\tauthor {\n\t\t\t\t\t\tlogin\n\t\t\t\t\t}\n\t\t\t\t\tcommits(last: 1) {\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t  nodes {\n\t\t\t\t\t\t  commit {\n\t\t\t\t\t\t\t  oid\n\t\t\t\t\t\t\t\tstatusCheckRollup {\n\t\t\t\t\t\t\t\t  contexts(last: 100) {\n\t\t\t\t\t\t\t\t    nodes {\n\t\t\t\t\t\t\t\t\t\t  ...on StatusContext {\n\t\t\t\t\t\t\t\t\t\t\t  context\n\t\t\t\t\t\t\t\t\t\t\t\tstate\n\t\t\t\t\t\t\t\t\t\t\t  targetUrl\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t...on CheckRun {\n\t\t\t\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t\t\t\t\t\tconclusion\n\t\t\t\t\t\t\t\t\t\t\t\tstartedAt\n\t\t\t\t\t\t\t\t\t\t\t\tcompletedAt\n\t\t\t\t\t\t\t\t\t\t\t\tdetailsUrl\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t  }\n\t\t\t\t\t}\n\t\t\t\t\turl\n\t\t\t\t\tbaseRefName\n\t\t\t\t\theadRefName\n\t\t\t\t\theadRepositoryOwner {\n\t\t\t\t\t\tlogin\n\t\t\t\t\t}\n\t\t\t\t\theadRepository {\n\t\t\t\t\t\tname\n\t\t\t\t\t}\n\t\t\t\t\tisCrossRepository\n\t\t\t\t\tisDraft\n\t\t\t\t\tmaintainerCanModify\n\t\t\t\t\treviewRequests(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\trequestedReviewer {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t...on User {\n\t\t\t\t\t\t\t\t\tlogin\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t...on Team {\n\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\treviews(last: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tauthor {\n\t\t\t\t\t\t\t  login\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tstate\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tassignees(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tlogin\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tlabels(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tprojectCards(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tproject {\n\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcolumn {\n\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tmilestone{\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}",
    "variables": {
        "headRefName": "conftest-app-metrics",
        "owner": "bitly",
        "repo": "bitly"
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id:
< X-Oauth-Client-Id:
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4950
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 50
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "repository": {
            "pullRequests": {
                "nodes": []
            }
        }
    }
}
* Request took 192.253972ms
* Request at 2020-09-18 16:23:59.699880362 -0600 MDT m=+0.832936377
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\t\tmutation PullRequestCreate($input: CreatePullRequestInput!) {\n\t\t\tcreatePullRequest(input: $input) {\n\t\t\t\tpullRequest {\n\t\t\t\t\tid\n\t\t\t\t\turl\n\t\t\t\t}\n\t\t\t}\n\t}",
    "variables": {
        "input": {
            "baseRefName": "master",
            "body": "",
            "draft": false,
            "headRefName": "conftest-app-metrics",
            "repositoryId": "MDEwOlJlcG9zaXRvcnkxNzYxMDE4",
            "title": "conftest app metrics"
        }
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id: 
< X-Oauth-Client-Id: 
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4949
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 51
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "createPullRequest": {
            "pullRequest": null
        }
    },
    "errors": [
        {
            "type": "UNPROCESSABLE",
            "path": [
                "createPullRequest"
            ],
            "locations": [
                {
                    "line": 3,
                    "column": 4
                }
            ],
            "message": "Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch"
        }
    ]
}
* Request took 458.545525ms
pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch

Activity

  1. added
    bug
    on Sep 18, 2020
  2. Mr-istov commented on Sep 21, 2020

    @Mr-istov

    In the new version 1.0.0 they have changed the implementation for gh pr create: #1706
    Quote from the PR: We no longer try to guess which is a suitable push target for the "head" branch. Instead, unless the user has already fully pushed their branch, we always present the user with a prompt:
    We never fork nor push without explicit user agreement anymore.

  3. mislav commented on Sep 21, 2020

    @mislav
    Contributor

    Hi @jharshman, thank you for reporting! Did you happen to already push the conftest-app-metrics branch to a remote before running pr create, and if so, to which remote did you push it to? Did the branch have extra commits on top of the base master branch?

  4. added
    more-info-needed
    on Sep 21, 2020
  5. a5anka commented on Sep 21, 2020

    @a5anka

    @mislav I also observed the same issue when I pushed to origin before creating the PR.

    Steps,

    1. git checkout -b feature-foo upstream/master
    2. git commit -am "Test commit"
    3. git push -u origin feature-foo
    4. gh pr create --fill

    Hope you can also reproduce the issue following the above steps.

  6. jharshman commented on Sep 21, 2020

    @jharshman
    Author

    @mislav I verified this issue in two ways. The first being allowing the cli to prompt me for which remote to push to, and the second being the way @a5anka described above. In both cases the fork was used and resulted in the same error message.

  7. removed
    more-info-needed
    on Sep 22, 2020
  8. mvdan commented on Sep 22, 2020

    @mvdan

    I can confirm this issue. I too had fully pushed my branch to my fork via git push -f -u mvdan, yet gh pr create --fill would still fail like in the original post. I had to give it all the explicit flags to make it work: gh pr create --fill --base=master --head=mvdan:less-debugdir.

  9. bhrutledge commented on Sep 22, 2020

    @bhrutledge

    Possibly related (or not, in which case I'm happy to file a separate issue).

    I'm seeing similar behavior from gh pr create --web, for a branch that was previously pushed to origin.

    For example:

    $ git status
    On branch fix-bugs
    Your branch is up to date with 'origin/fix-bugs'.
    
    $ git remote -v
    origin  [email protected]:bhrutledge/twine.git (fetch)
    origin  [email protected]:bhrutledge/twine.git (push)
    upstream        https://github.com/pypa/twine.git (fetch)
    upstream        https://github.com/pypa/twine.git (push)
    
    $ gh pr create --web
    Opening github.com/pypa/twine/compare/master...fix-bugs in your browser.
    

    I would have expected:

    Opening github.com/pypa/twine/compare/master...bhrutledge:fix-bugs in your browser.
    

    I can achieve that with:

    $ gh pr create --head $(gh config get -h github.com user):$(git rev-parse --abbrev-ref HEAD) --web
    Opening github.com/pypa/twine/compare/master...bhrutledge:fix-bugs in your browser.
    

    This changed with the upgrade to 1.0, i.e., I was seeing the expected behavior in the last version.

  10. mislav commented on Sep 22, 2020

    @mislav
    Contributor

    Thank you for all the info! I'm thinking that this might be related or identical to #1762

  11. changed the title [-]PR Create - GraphQL error: Head sha can't be blank[/-] [+]PR Create - GraphQL error due to wrong head branch detected[/+] on Sep 22, 2020
  12. jharshman commented on Sep 22, 2020

    @jharshman
    Author

    @mislav interestingly enough, it functioned as expected when the CLI was used to create the fork as well.

  13. self-assigned this
    on Sep 24, 2020
  14. geerlingguy commented on Sep 24, 2020

    @geerlingguy

    I have been running into this issue on all my repos for the past couple days since upgrading to the latest version of gh. It's quite annoying as I really only use gh to create PRs, and that functionality seems broken (was working fine for months).

    Is there any workaround? For now I'm having to go to the browser to create PRs like it's 1999.

  15. bhrutledge commented on Sep 24, 2020

    @bhrutledge

    @geerlingguy I'm working around this by using the --head option, as noted in #1820 (comment) (and in the preceding comment). I think you could define an alias (probably with the --shell option) to shorten that up.

  16. mislav commented on Sep 29, 2020

    @mislav
    Contributor

    Thank you everyone for your reports and patience! Currently fixed in trunk; we will cut a release soon 👍

  17. lszomoru commented on Oct 2, 2020

    @lszomoru

    @mislav, do you have an ETA on the release?
    Also do you know when the GH Actions agents will be updated as we are using the GH CLI from an action. Thanks!

  18. added a commit that references this issue on Oct 2, 2020
  19. johnpapa commented on Oct 15, 2020

    @johnpapa

    it appears GH 1.1.0 fixes this

  20. cveneziani commented on Oct 22, 2020

    @cveneziani

    Currently using gh version 1.1.0 (2020-10-06) and I still experience this error.

  21. mislav commented on Oct 23, 2020

    @mislav
    Contributor

    @cveneziani Please open another issue! Also include your git remote and branch setup in your report 🙇

  22. armsp commented on Nov 14, 2020

    @armsp

    @mislav I have the same issue when I try this from a github action worker.
    I commands I have used inside the worker are -

    git checkout -b patch
    git add .
    git commit -m "adding data file"
    gh pr create --title "Latest run Test Report" --body "Report Results" --head armsp:patch
    

    Is this the correct way to make a PR from a local git branch to the remote master/main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions