Skip to content

gh pr checkout panics if the PR repo does not exist #3696

@zneix

Description

@zneix

Describe the bug

Upon trying to checkout to a pr with gh pr checkout 2556 in Chatterino/chatterino2 you'll get a panic and gh cli will crash because for that specific Pull Request fork on which PR branch was on got deleted.

Version: gh version 1.10.3 (2021-05-22)

Steps to reproduce the behavior

  1. Go to cloned Chatterino/chatterino2 repo.
  2. Type gh pr checkout 2556
  3. See gh cli panic and crash

Expected vs actual behavior

gh cli should check out to the PR's branch, similar to how the following command would do it: git fetch origin pull/$pr/head:pr/$pr && git checkout pr/$pr (where $pr is the PR number, e.g. 2556 in this scenario).
As of writing the issue, gh cli simply panics.

Logs

zneix@uds ~/g/chatterino2 (master)$ gh --version
gh version 1.10.3 (2021-05-22)
https://github.com/cli/cli/releases/tag/v1.10.3
zneix@uds ~/g/chatterino2 (master)$ gh pr checkout 2556
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x5586b3af1164]

goroutine 1 [running]:
github.com/cli/cli/pkg/cmd/pr/checkout.checkoutRun(0xc000146af0, 0xc000497680, 0x0)
        github.com/cli/cli/pkg/cmd/pr/checkout/checkout.go:100 +0xac4
github.com/cli/cli/pkg/cmd/pr/checkout.NewCmdCheckout.func1(0xc0003cc000, 0xc0008154d0, 0x1, 0x1, 0x0, 0x0)
        github.com/cli/cli/pkg/cmd/pr/checkout/checkout.go:61 +0x166
github.com/spf13/cobra.(*Command).execute(0xc0003cc000, 0xc0008154b0, 0x1, 0x1, 0xc0003cc000, 0xc0008154b0)
        github.com/spf13/cobra@v1.1.3/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000b3400, 0xc0008153a0, 0x5586b3bb7501, 0xd)
        github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
main.mainRun(0xc00002e0b8)
        github.com/cli/cli/cmd/gh/main.go:166 +0x676
main.main()
        github.com/cli/cli/cmd/gh/main.go:46 +0x25
zneix@uds ~/g/chatterino2 (master) [2]$ git remote -v
fork    gh:/zneix/chatterino2 (fetch)
fork    gh:/zneix/chatterino2 (push)
origin  gh:/Chatterino/chatterino2 (fetch)
origin  gh:/Chatterino/chatterino2 (push)
zneix@uds ~/g/chatterino2 (master)$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
zneix@uds ~/g/chatterino2 (master)$

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority-2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions