Skip to content

git_checkout_pull_request(): pass repo arg to git_branch_exists() - #248

Merged
jeroen merged 1 commit into
r-lib:mainfrom
zkamvar:patch-1
Jul 23, 2025
Merged

git_checkout_pull_request(): pass repo arg to git_branch_exists()#248
jeroen merged 1 commit into
r-lib:mainfrom
zkamvar:patch-1

Conversation

@zkamvar

@zkamvar zkamvar commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

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.

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

Created on 2025-07-23 with reprex v2.1.1

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>
@jeroen
jeroen merged commit 561f059 into r-lib:main Jul 23, 2025
11 checks passed
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.

2 participants