Skip to content

fix(pr): look up the remote branch directly when creating a PR - #1571

Open
jasoncheng-jora wants to merge 1 commit into
pwntester:masterfrom
jasoncheng-jora:fix/remote-branch-lookup
Open

jasoncheng-jora wants to merge 1 commit into
pwntester:masterfrom
jasoncheng-jora:fix/remote-branch-lookup

Conversation

@jasoncheng-jora

Copy link
Copy Markdown

Describe what this PR does / why we need it

In a repository with more than 100 branches, :Octo pr create reports a branch that is pushed as missing:

Remote branch '<branch>' does not exist. Push local one?  [Yes] [No] [Cancel]

The prompt defaults to No, so pressing Enter aborts with Aborting PR creation.

create_pr never asked GitHub about the branch. It downloaded a page of branch names and searched it locally:

  • M.repository fetched refs(last:100, refPrefix: "refs/heads/")
  • create_pr scanned info.refs.nodes for the current branch

GitHub caps that connection at 100 entries and last: takes the final 100 by name, so in a 267-branch repository only m… through w… came back and every branch earlier in the alphabet looked unpushed.

Raising the page size is not possible (100 is GitHub's per-page cap), and orderBy: {field: TAG_COMMIT_DATE} does not help — branch refs come back alphabetically regardless.

Does this pull request fix one issue?

Fixes #1570

Describe how you did it

Ask GitHub about the single ref instead of a page of them:

  • lua/octo/gh/queries.lua — added M.ref, a ref(qualifiedName:) lookup
  • lua/octo/utils.lua — added M.remote_branch_exists(repo, branch)
  • lua/octo/commands.lua — the 20-line scan becomes one call; the info nil-guard that the removed block carried is kept, and moved up to where info is first used
  • lua/octo/gh/queries.lua — dropped refs from the repository query, which had no remaining consumer

Net effect on traffic: get_repo_info no longer pulls 100 branch names it almost never read, and pr create spends one small query on the branch that actually matters.

Describe how to verify it

lua/tests/plenary/remote_branch_spec.lua covers the behaviour, including the regression guard that the repository query no longer pages branches:

nvim --headless -u lua/tests/minimal_init.vim \
  -c "PlenaryBustedFile lua/tests/plenary/remote_branch_spec.lua"

Manually, in a repository with more than 100 branches: push a branch sorting early alphabetically (e.g. aaa-test) and run :Octo pr create. Before this change it prompts to push an already-pushed branch; after it goes straight to the PR buffer. A genuinely unpushed branch still gets the prompt.

Special notes for reviews

The prompt for genuinely unpushed branches is deliberately preserved — a fix that merely suppressed it would have lost the "you forgot to push" warning. There is a test for that case.

local_branch is still derived from git rev-parse --abbrev-ref HEAD exactly as before, so no behaviour changes for detached HEAD or forks beyond the lookup itself.

Checklist

  • Passing tests and linting standards
  • Documentation updates in README.md and doc/octo.txt

Verified locally against af24116:

  • Full plenary suite: 391 passed, 0 failed, 0 errors across 21 spec files
  • stylua --check on all touched files: clean
  • make check (lua-language-server, --checklevel=Information): 402 problems in 40 files, byte-identical to the count on an unpatched upstream/master worktree in the same environment — no new diagnostics

No documentation change: this is a bug fix with no user-facing configuration or command surface.

🤖 Generated with Claude Code

`create_pr` decided whether the local branch was already pushed by scanning
`refs(last:100)` from the repository query. GitHub caps that connection at 100
entries, so in a repository with more branches only the last 100 by name come
back, and anything earlier in the alphabet looks unpushed. `:Octo pr create`
then asks "Remote branch '<name>' does not exist. Push local one?" about a
branch that is pushed, and aborts on the default answer.

Ask GitHub about the single ref instead, via `ref(qualifiedName:)`, which is
exact regardless of how many branches the repository has. The `refs` page has
no remaining consumer, so drop it from the repository query rather than fetch
100 branch names on every repo info lookup.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

:Octo pr create reports a pushed branch as missing in repos with more than 100 branches

1 participant