fix(pr): look up the remote branch directly when creating a PR - #1571
Open
jasoncheng-jora wants to merge 1 commit into
Open
jasoncheng-jora wants to merge 1 commit into
jasoncheng-jora wants to merge 1 commit into
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
In a repository with more than 100 branches,
:Octo pr createreports a branch that is pushed as missing:The prompt defaults to
No, so pressing Enter aborts withAborting PR creation.create_prnever asked GitHub about the branch. It downloaded a page of branch names and searched it locally:M.repositoryfetchedrefs(last:100, refPrefix: "refs/heads/")create_prscannedinfo.refs.nodesfor the current branchGitHub caps that connection at 100 entries and
last:takes the final 100 by name, so in a 267-branch repository onlym…throughw…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— addedM.ref, aref(qualifiedName:)lookuplua/octo/utils.lua— addedM.remote_branch_exists(repo, branch)lua/octo/commands.lua— the 20-line scan becomes one call; theinfonil-guard that the removed block carried is kept, and moved up to whereinfois first usedlua/octo/gh/queries.lua— droppedrefsfrom the repository query, which had no remaining consumerNet effect on traffic:
get_repo_infono longer pulls 100 branch names it almost never read, andpr createspends one small query on the branch that actually matters.Describe how to verify it
lua/tests/plenary/remote_branch_spec.luacovers 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_branchis still derived fromgit rev-parse --abbrev-ref HEADexactly as before, so no behaviour changes for detached HEAD or forks beyond the lookup itself.Checklist
Verified locally against
af24116:stylua --checkon all touched files: cleanmake check(lua-language-server,--checklevel=Information): 402 problems in 40 files, byte-identical to the count on an unpatchedupstream/masterworktree in the same environment — no new diagnosticsNo documentation change: this is a bug fix with no user-facing configuration or command surface.
🤖 Generated with Claude Code