git_checkout_pull_request(): pass repo arg to git_branch_exists() - #248
Merged
Conversation
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>
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.
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.Created on 2025-07-23 with reprex v2.1.1