From 3e7f33531602efc9d10398a3330ee910ca6191f4 Mon Sep 17 00:00:00 2001 From: Louis DeLosSantos Date: Sun, 2 Feb 2025 08:20:07 -0500 Subject: [PATCH] fix: allow pr checkout from non-default repository (#827) 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 Co-authored-by: Will Dean <57733339+wd60622@users.noreply.github.com> --- lua/octo/reviews/init.lua | 2 +- lua/octo/utils.lua | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/octo/reviews/init.lua b/lua/octo/reviews/init.lua index 5a203e53..ebf3846e 100644 --- a/lua/octo/reviews/init.lua +++ b/lua/octo/reviews/init.lua @@ -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 diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua index 2d68578d..869d4ff4 100644 --- a/lua/octo/utils.lua +++ b/lua/octo/utils.lua @@ -562,6 +562,7 @@ function M.checkout_pr(pr_number) end ---@class CheckoutPrSyncOpts +---@field repo string ---@field pr_number number ---@field timeout number @@ -574,7 +575,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)