Skip to content

Commit d4a810c

Browse files
authored
git_checkout_pull_request(): pass repo arg to git_branch_exists()
I noticed a bug when attempting to check out a pull request programmatically in a repo in a temporary directory. It turned out that the repo argument was not being passed to `git_branch_exists`. The workaround at the moment, is to run this code in the git directory. ``` r print(tmp <- tempfile()) #> [1] "/var/folders/t2/chsckzh12t38xqwg17xslwr80000gn/T//RtmpCfmpAw/file888d6ffbc3dc" print(getwd()) #> [1] "/private/var/folders/t2/chsckzh12t38xqwg17xslwr80000gn/T/Rtmpys1Ric/reprex-82ee7ec139de-fussy-agama" gert::git_clone("https://github.com/r-lib/gert.git", tmp) gert::git_checkout_pull_request(pr = 227, repo = tmp) #> Error in libgit2::git_repository_open_ext: could not find repository at '/private/var/folders/t2/chsckzh12t38xqwg17xslwr80000gn/T/Rtmpys1Ric/reprex-82ee7ec139de-fussy-agama' withr::with_dir(tmp, { gert::git_checkout_pull_request(pr = 227) }) #> Creating new branch: pr/227 ``` <sup>Created on 2025-07-23 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
1 parent 17459fd commit d4a810c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

R/pr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.'){
1717
local_branch <- sprintf("pr/%s", pr)
1818
remote_branch <- sprintf("%s/pr/%s", remote, pr)
1919
git_fetch_pull_requests(pr = pr, remote = remote, repo = repo)
20-
if(git_branch_exists(local_branch)){
20+
if(git_branch_exists(local_branch, repo = repo)){
2121
inform("Continuing on existing pr branch: %s", local_branch)
2222
git_branch_checkout(local_branch, repo = repo)
2323
git_pull(repo = repo)

0 commit comments

Comments
 (0)