forked from r-lib/gert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr.R
More file actions
39 lines (38 loc) · 1.32 KB
/
Copy pathpr.R
File metadata and controls
39 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' GitHub Wrappers
#'
#' Fetch and checkout pull requests.
#'
#' By default `git_fetch_pull_requests` will download all PR branches. To
#' remove these again simply use `git_fetch(prune = TRUE)`.
#'
#' @export
#' @rdname github
#' @inheritParams git_fetch
#' @param pr number with PR to fetch or check out. Use `"*"` to fetch all
#' pull requests.
git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.'){
pr <- as.character(pr)
if(!length(remote))
remote <- git_info(repo)$remote
local_branch <- sprintf("pr/%s", pr)
remote_branch <- sprintf("%s/pr/%s", remote, pr)
git_fetch_pull_requests(pr = pr, remote = remote, repo = repo)
if(git_branch_exists(local_branch, repo = repo)){
inform("Continuing on existing pr branch: %s", local_branch)
git_branch_checkout(local_branch, repo = repo)
git_pull(repo = repo)
} else {
inform("Creating new branch: %s", local_branch)
git_branch_create(local_branch, remote_branch, checkout = TRUE, repo = repo)
}
}
#' @export
#' @rdname github
git_fetch_pull_requests <- function(pr = '*', remote = NULL, repo = '.'){
pr <- as.character(pr)
if(!length(remote))
remote <- git_info(repo)$remote
refspec <- sprintf('+refs/pull/%s/head:refs/remotes/%s/pr/%s', pr, remote, pr)
git_fetch(remote = remote, refspec = refspec, repo = repo)
invisible(refspec)
}