Skip to content

Commit

Permalink
fix: allow pr checkout from non-default repository
Browse files Browse the repository at this point in the history
When working in a mulit-remote pull requests may come from separate
repositories.

Octo currently lets you list and view PRs from a configurable
repository.
However, when it comes to checking out a review branch, it only looks at
the current default repository via `gh cli`.

This change simply provides the PR's repository string to `gh pr
checkout` command so non-default repository branches can be checked out
as well.

Prior to this commit if you did something like `Octo pr edit 1234
owner/repo-b` where `repo-b` is not the default repository and tried to
start a review, the PR branch would not be checked out, since its in the
non-default repository.

Signed-off-by: ldelossa <[email protected]>
  • Loading branch information
ldelossa committed Jan 28, 2025
1 parent 1d2982f commit 7df20c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lua/octo/reviews/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function Review:initiate(opts)
if conf.use_local_fs and not utils.in_pr_branch(pr) then
local choice = vim.fn.confirm("Currently not in PR branch, would you like to checkout?", "&Yes\n&No", 2)
if choice == 1 then
utils.checkout_pr_sync { pr_number = pr.number, timeout = conf.timeout }
utils.checkout_pr_sync { repo = pr.repo, pr_number = pr.number, timeout = conf.timeout }
end
end

Expand Down
3 changes: 2 additions & 1 deletion lua/octo/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ function M.checkout_pr(pr_number)
end

---@class CheckoutPrSyncOpts
---@field repo string
---@field pr_number number
---@field timeout number

Expand All @@ -564,7 +565,7 @@ function M.checkout_pr_sync(opts)
Job:new({
enable_recording = true,
command = "gh",
args = { "pr", "checkout", opts.pr_number },
args = { "pr", "checkout", opts.pr_number, "--repo", opts.repo },
on_exit = vim.schedule_wrap(function()
local output = vim.fn.system "git branch --show-current"
M.info("Switched to " .. output)
Expand Down

0 comments on commit 7df20c5

Please sign in to comment.