88# ' @family git
99# ' @inheritParams git_open
1010# ' @useDynLib gert R_git_branch_current
11- git_branch <- function (repo = ' .' ){
11+ git_branch <- function (repo = ' .' ) {
1212 repo <- git_open(repo )
1313 .Call(R_git_branch_current , repo )
1414}
1515
1616# ' @export
1717# ' @rdname git_branch
1818# ' @useDynLib gert R_git_branch_list
19- git_branch_list <- function (local = NULL , repo = ' .' ){
19+ git_branch_list <- function (local = NULL , repo = ' .' ) {
2020 repo <- git_open(repo )
2121 local <- as.logical(local )
2222 .Call(R_git_branch_list , repo , local )
@@ -28,21 +28,29 @@ git_branch_list <- function(local = NULL, repo = '.'){
2828# ' @param force ignore conflicts and overwrite modified files
2929# ' @param orphan if branch does not exist, checkout unborn branch
3030# ' @useDynLib gert R_git_checkout_branch R_git_checkout_unborn
31- git_branch_checkout <- function (branch , force = FALSE , orphan = FALSE , repo = ' .' ){
31+ git_branch_checkout <- function (
32+ branch ,
33+ force = FALSE ,
34+ orphan = FALSE ,
35+ repo = ' .'
36+ ) {
3237 repo <- git_open(repo )
3338 branch <- as.character(branch )
3439 force <- as.logical(force )
35- if (! git_branch_exists(branch , repo = repo )){
36- if (isTRUE(orphan )){
40+ if (! git_branch_exists(branch , repo = repo )) {
41+ if (isTRUE(orphan )) {
3742 ref <- paste0(' refs/heads/' , branch )
3843 .Call(R_git_checkout_unborn , repo , ref )
3944 return (ref )
4045 }
4146 all_branches <- subset(git_branch_list(repo = repo ), local == FALSE )$ name
4247 candidate <- sub(" ^[^/]+/" , " " , all_branches ) == branch
43- if (sum(candidate ) > 1 ){
44- stop(sprintf(" Local branch '%s' does not exist and multiple remote candidates found." , branch ))
45- } else if (sum(candidate ) == 0 ){
48+ if (sum(candidate ) > 1 ) {
49+ stop(sprintf(
50+ " Local branch '%s' does not exist and multiple remote candidates found." ,
51+ branch
52+ ))
53+ } else if (sum(candidate ) == 0 ) {
4654 stop(sprintf(" No local or remote branch '%s' found." , branch ))
4755 } else {
4856 remote_branch <- unname(all_branches [candidate ])
@@ -59,7 +67,13 @@ git_branch_checkout <- function(branch, force = FALSE, orphan = FALSE, repo = '.
5967# ' @param ref string with a branch/tag/commit
6068# ' @param checkout move HEAD to the newly created branch
6169# ' @param force overwrite existing branch
62- git_branch_create <- function (branch , ref = " HEAD" , checkout = TRUE , force = FALSE , repo = ' .' ){
70+ git_branch_create <- function (
71+ branch ,
72+ ref = " HEAD" ,
73+ checkout = TRUE ,
74+ force = FALSE ,
75+ repo = ' .'
76+ ) {
6377 repo <- git_open(repo )
6478 branch <- as.character(branch )
6579 ref <- as.character(ref )
@@ -71,7 +85,7 @@ git_branch_create <- function(branch, ref = "HEAD", checkout = TRUE, force = FAL
7185# ' @export
7286# ' @rdname git_branch
7387# ' @useDynLib gert R_git_delete_branch
74- git_branch_delete <- function (branch , repo = ' .' ){
88+ git_branch_delete <- function (branch , repo = ' .' ) {
7589 repo <- git_open(repo )
7690 branch <- as.character(branch )
7791 .Call(R_git_delete_branch , repo , branch )
@@ -82,7 +96,7 @@ git_branch_delete <- function(branch, repo = '.'){
8296# ' @rdname git_branch
8397# ' @useDynLib gert R_git_branch_move
8498# ' @param new_branch target name of the branch once the move is performed; this name is validated for consistency.
85- git_branch_move <- function (branch , new_branch , force = FALSE , repo = ' .' ){
99+ git_branch_move <- function (branch , new_branch , force = FALSE , repo = ' .' ) {
86100 repo <- git_open(repo )
87101 branch <- as.character(branch )
88102 new_branch <- as.character(new_branch )
@@ -92,9 +106,9 @@ git_branch_move <- function(branch, new_branch, force = FALSE, repo = '.'){
92106
93107# ' @export
94108# ' @rdname git_branch
95- git_branch_fast_forward <- function (ref , repo = ' .' ){
109+ git_branch_fast_forward <- function (ref , repo = ' .' ) {
96110 analysis <- git_merge_analysis(ref = ref , repo = repo )
97- if (analysis != " fastforward" )
111+ if (analysis != " fastforward" )
98112 stop(" Branch cannot be fast-forwarded. Use git_merge() instead" )
99113 git_branch_set_target(ref = ref , repo = repo )
100114}
@@ -103,10 +117,14 @@ git_branch_fast_forward <- function(ref, repo = '.'){
103117# ' @rdname git_branch
104118# ' @param upstream remote branch from [git_branch_list], for example `"origin/master"`
105119# ' @useDynLib gert R_git_branch_set_upstream
106- git_branch_set_upstream <- function (upstream , branch = git_branch(repo ), repo = ' .' ){
120+ git_branch_set_upstream <- function (
121+ upstream ,
122+ branch = git_branch(repo ),
123+ repo = ' .'
124+ ) {
107125 repo <- git_open(repo )
108126 stopifnot(is.character(upstream ))
109- if (! git_branch_exists(upstream , local = FALSE , repo = repo ))
127+ if (! git_branch_exists(upstream , local = FALSE , repo = repo ))
110128 stop(sprintf(" No remote branch found: %s, maybe fetch first?" , upstream ))
111129 .Call(R_git_branch_set_upstream , repo , upstream , branch )
112130 git_repo_path(repo )
@@ -117,15 +135,15 @@ git_branch_set_upstream <- function(upstream, branch = git_branch(repo), repo =
117135# ' @param local set TRUE to only check for local branches, FALSE to check for remote
118136# ' branches. Use NULL to return all branches.
119137# ' @useDynLib gert R_git_branch_exists
120- git_branch_exists <- function (branch , local = TRUE , repo = ' .' ){
138+ git_branch_exists <- function (branch , local = TRUE , repo = ' .' ) {
121139 repo <- git_open(repo )
122140 branch <- as.character(branch )
123141 local <- as.logical(local )
124142 .Call(R_git_branch_exists , repo , branch , local )
125143}
126144
127145# ' @useDynLib gert R_git_branch_set_target
128- git_branch_set_target <- function (ref , branch , repo ){
146+ git_branch_set_target <- function (ref , branch , repo ) {
129147 repo <- git_open(repo )
130148 ref <- as.character(ref )
131149 .Call(R_git_branch_set_target , repo , ref )
0 commit comments