seachicken/gh-poi

Misses a branch for a PR I've merged

Closed this issue · 2 comments

Describe the bug

Hey, first of all thanks for providing this extension, I found it when I was going to learn how to create a gh extension for a terminal one-liner I cobbled together:

gh pr list -L 1000 --author @me --state merged --json headRefName --jq '.[] | .headRefName' | xargs -I @ bash -c "git for-each-ref refs/heads --format='%(refname:short)' | grep '@'"

OK, now for the bug report:

My one-liner lists the following branches from merged PRs for the repo I'm currently working in:

armcknight/test/disabling
armcknight/fix/trending-movies-build
armcknight/ci/disable-trending-movies-caching
armcknight/fix/release-format
armcknight/fix/test-app-caching
armcknight/ref/json-serialization-error-reporting

and I tried running gh poi --dry-run and it reported it would've deleted the following local branches:

Deleted branches
  armcknight/ci/disable-trending-movies-caching
    └─ #2479  https://github.com/getsentry/sentry-cocoa/pull/2479 armcknight
  armcknight/fix/release-format
    └─ #2470  https://github.com/getsentry/sentry-cocoa/pull/2470 armcknight
  armcknight/fix/test-app-caching
    └─ #2412  https://github.com/getsentry/sentry-cocoa/pull/2412 armcknight
  armcknight/fix/trending-movies-build
    └─ #2480  https://github.com/getsentry/sentry-cocoa/pull/2480 armcknight
  armcknight/test/disabling
    └─ #2603  https://github.com/getsentry/sentry-cocoa/pull/2603 armcknight

However, there's one branch it would not have deleted: armcknight/ref/json-serialization-error-reporting .

The URL that is returned for that ref from gh pr list -L 1000 --author @me --state merged --json headRefName,url is getsentry/sentry-cocoa#2355 which is indeed merged.

One guess I had was that the base ref at the time was master, but we've since changed the default base to main. But, all the others were also merged into master before we made that switch.

Another guess is that I used ref in the branch name for refactor, I wonder if you're filtering out ref since that's also a special word used by git.

It could also be that the PR is too old and you're fetching a limited number of PRs that doesn't include this branch.

Your Environment

  • OS: macOS 12.6
  • gh (Check with gh --version):
❯ gh --version
gh version 2.10.1 (2022-05-10)
https://github.com/cli/cli/releases/tag/v2.10.1
  • gh-poi (Check with gh ext ls):
❯ gh extension ls
gh poi  seachicken/gh-poi  v0.9.0

(Note: gh ext ls didn't work for me, is that in a newer version of gh?)

Thank you for the report 😄
Are branches that were not deleted associated with PRs?
Do you see something like this?

Branches not deleted
  armcknight/ref/json-serialization-error-reporting
    └─ #2355  https://github.com/getsentry/sentry-cocoa/pull/2355 armcknight

If the PR has been merged, but the local commit is further along than the latest commit SHA of the PR, the branch is not deleted so that the changes are not lost. Is this the case?

---
title: Example
---
gitGraph
   commit
   commit
   branch issue1
   checkout issue1
   commit
   commit
   checkout main
   merge issue1
   checkout issue1
   commit
Loading

Another guess is that I used ref in the branch name for refactor, I wonder if you're filtering out ref since that's also a special word used by git.

No problem branch name with ref

gh ext ls didn't work for me, is that in a newer version of gh?

Yes, ext is available in a slightly newer version of gh

Hi @seachicken thanks for responding with those details. You are correct that it is not displayed with an associated PR. Looking at the commits it's currently referencing, your guess looks right, there are different changes locally than was in the PR. Sorry for the mixup, I'll try to be more careful with not reusing branch refs/names next time!