seachicken / gh-poi

✨ Safely clean up your local branches
https://dev.to/seachicken/safely-clean-up-your-local-branches-9i3
MIT License
642 stars 17 forks source link

`panic: runtime error: index out of range [0] with length 0` #27

Closed ShadowJonathan closed 2 years ago

ShadowJonathan commented 2 years ago

Describe the bug

(synapse) jonathan@jon:~/dev/synapse$ gh poi
⠼ Fetching pull requests...panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.isFullyMerged({0x0, {0xc0000b631a, 0x7}, {0x62e8d0, 0x0, 0x0}, {0xc00021c480, 0x1, 0x1}, 0x0}, ...)
        /home/runner/work/gh-poi/gh-poi/poi.go:311 +0xe5
main.getDeleteStatus({0x0, {0xc0000b631a, 0x7}, {0x62e8d0, 0x0, 0x0}, {0xc00021c480, 0x1, 0x1}, 0x0}, ...)
        /home/runner/work/gh-poi/gh-poi/poi.go:295 +0x158
main.checkDeletion({0xc0000d5500, 0x53, 0xa}, {0xc000190030, 0x25})
        /home/runner/work/gh-poi/gh-poi/poi.go:275 +0x11e
main.GetBranches({0x547f10, 0x62e8d0}, 0x0)
        /home/runner/work/gh-poi/gh-poi/poi.go:120 +0x24d
main.runMain(0x0)
        /home/runner/work/gh-poi/gh-poi/main.go:42 +0x165
main.main()
        /home/runner/work/gh-poi/gh-poi/main.go:26 +0xbb

I'm not entirely sure how to fetch more information, please suggest me git commands to run to gain more info.

Your Environment

seachicken commented 2 years ago

Thanks for reporting the issue. Hmmm... I don't know how to reproduce this. From what I can tell from the stack trace, there seems to be a local branch where no commits exist. https://github.com/seachicken/gh-poi/blob/6b42a8af2907b331c4cd3703ba3aab6ee676cb29/poi.go#L311

ShadowJonathan commented 2 years ago

That is entirely possible, I have branches for which I have stashes, but no commits.

If possible, I still suggest not assuming any branches have divergent commits from any other, it's possible these are merged locally and such, or simply held in place as "todo branches".

seachicken commented 2 years ago

The case of creating a local "to do branch" seems to be fine. I have noticed the same error when there is a PR that merges from the default branch (e.g. develop) to another branch (e.g. main).

⠏ Fetching pull requests...panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.isFullyMerged({0x0, {0xc00019c1fc, 0x4}, {0x122c4a8, 0x0, 0x0}, {0xc0002543c0, 0x1, 0x1}, 0x0}, ...)
        /Users/seito/.local/share/gh/extensions/gh-poi/poi.go:312 +0xe5
main.getDeleteStatus({0x0, {0xc00019c1fc, 0x4}, {0x122c4a8, 0x0, 0x0}, {0xc0002543c0, 0x1, 0x1}, 0x0}, ...)
        /Users/seito/.local/share/gh/extensions/gh-poi/poi.go:296 +0x158
main.checkDeletion({0xc00024e500, 0xc, 0xa}, {0x0, 0x0})
        /Users/seito/.local/share/gh/extensions/gh-poi/poi.go:276 +0x11e
main.GetBranches({0x1145e30, 0x122c4a8}, 0x1)
        /Users/seito/.local/share/gh/extensions/gh-poi/poi.go:120 +0x24d
main.runMain(0x1)
        /Users/seito/.local/share/gh/extensions/gh-poi/main.go:42 +0x165
main.main()
        /Users/seito/.local/share/gh/extensions/gh-poi/main.go:26 +0xbb

I don't know if this will be fixed once I get rid of this case, but I will try to fix this as it is also a problem.

seachicken commented 2 years ago

Fixed a problem that is probably related to this. You can upgrade to the latest version by using gh extension upgrade poi.

ShadowJonathan commented 2 years ago

I'll check in a second if that fixes it

ShadowJonathan commented 2 years ago

Seems to be fixed now, thanks!