Skip to content

Commit 14acfad

Browse files
authored
chore: air format (#255)
1 parent 8932eda commit 14acfad

21 files changed

Lines changed: 301 additions & 102 deletions

R/archive.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ git_archive_internal <- function(outfile, repo) {
2828
git_stash_save(repo = repo)
2929
on.exit(git_stash_pop(repo = repo))
3030
},
31-
GIT_ENOTFOUND = function(e) {
32-
}
31+
GIT_ENOTFOUND = function(e) {}
3332
)
3433
files <- git_ls(repo = repo)$path
3534
wd <- getwd()

R/branch.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ git_branch_move <- function(branch, new_branch, force = FALSE, repo = '.') {
112112
#' @rdname git_branch
113113
git_branch_fast_forward <- function(ref, repo = '.') {
114114
analysis <- git_merge_analysis(ref = ref, repo = repo)
115-
if (analysis != "fastforward")
115+
if (analysis != "fastforward") {
116116
stop("Branch cannot be fast-forwarded. Use git_merge() instead")
117+
}
117118
git_branch_set_target(ref = ref, repo = repo)
118119
}
119120

@@ -128,8 +129,9 @@ git_branch_set_upstream <- function(
128129
) {
129130
repo <- git_open(repo)
130131
stopifnot(is.character(upstream))
131-
if (!git_branch_exists(upstream, local = FALSE, repo = repo))
132+
if (!git_branch_exists(upstream, local = FALSE, repo = repo)) {
132133
stop(sprintf("No remote branch found: %s, maybe fetch first?", upstream))
134+
}
133135
.Call(R_git_branch_set_upstream, repo, upstream, branch)
134136
git_repo_path(repo)
135137
}

R/commit.R

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ git_commit <- function(message, author = NULL, committer = NULL, repo = '.') {
7474
}
7575
stopifnot(is.character(message), length(message) == 1)
7676
status <- git_status(repo = repo)
77-
if (!any(status$staged))
77+
if (!any(status$staged)) {
7878
stop("No staged files to commit. Run git_add() to select files.")
79+
}
7980
merge_parents <- git_merge_parent_heads(repo = repo)
8081
.Call(R_git_commit_create, repo, message, author, committer, merge_parents)
8182
}
@@ -94,10 +95,14 @@ git_commit_all <- function(
9495
changes <- unstaged$file[
9596
unstaged$status %in% c("modified", "renamed", "typechange")
9697
]
97-
if (length(changes)) git_add(changes, repo = repo)
98+
if (length(changes)) {
99+
git_add(changes, repo = repo)
100+
}
98101

99102
deleted <- unstaged$file[unstaged$status == "deleted"]
100-
if (length(deleted)) git_rm(deleted, repo = repo)
103+
if (length(deleted)) {
104+
git_rm(deleted, repo = repo)
105+
}
101106

102107
git_commit(
103108
message = message,
@@ -209,7 +214,9 @@ git_log <- function(ref = "HEAD", max = 100, after = NULL, repo = ".") {
209214
repo <- git_open(repo)
210215
ref <- as.character(ref)
211216
max <- as.integer(max)
212-
if (length(after)) after <- as.POSIXct(after)
217+
if (length(after)) {
218+
after <- as.POSIXct(after)
219+
}
213220
.Call(R_git_commit_log, repo, ref, max, after)
214221
}
215222

@@ -224,6 +231,7 @@ git_stat_files <- function(files, ref = "HEAD", max = NULL, repo = '.') {
224231
}
225232

226233
assert_string <- function(x) {
227-
if (!is.character(x) || !length(x))
234+
if (!is.character(x) || !length(x)) {
228235
stop("Argument must be a string of length 1")
236+
}
229237
}

R/errors.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ raise_libgit2_error <- function(code, message, where = "", kclass = 0) {
1111

1212
libgit2_error_name <- function(x) {
1313
out <- which(libgit2_error_codes == x)
14-
if (length(out)) return(names(out))
14+
if (length(out)) {
15+
return(names(out))
16+
}
1517
return("UNKNOWN_ERROR_CODE")
1618
}
1719

R/fetch.R

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ git_fetch <- function(
3636
) {
3737
repo <- git_open(repo)
3838
info <- git_info(repo)
39-
if (!length(remote)) remote <- info$remote
39+
if (!length(remote)) {
40+
remote <- info$remote
41+
}
4042
remote <- as.character(remote)
4143
if (!length(remote) || is.na(remote)) {
4244
if (is.na(match("origin", git_remote_list(repo = repo)$name))) {
@@ -77,7 +79,9 @@ git_remote_ls <- function(
7779
) {
7880
repo <- git_open(repo)
7981
info <- git_info(repo)
80-
if (!length(remote)) remote <- info$remote
82+
if (!length(remote)) {
83+
remote <- info$remote
84+
}
8185
remote <- as.character(remote)
8286
if (!length(remote) || is.na(remote)) {
8387
if (is.na(match("origin", git_remote_list(repo = repo)$name))) {
@@ -115,7 +119,9 @@ git_push <- function(
115119
info <- git_info(repo)
116120
verbose <- as.logical(verbose)
117121

118-
if (!length(remote)) remote <- info$remote
122+
if (!length(remote)) {
123+
remote <- info$remote
124+
}
119125

120126
remote <- as.character(remote)
121127

@@ -136,17 +142,22 @@ git_push <- function(
136142
refs <- refs[!grepl("^refs/pull", refs)]
137143
refspec <- paste0(refs, ":", refs)
138144
}
139-
if (!length(refspec)) refspec <- info$head
145+
if (!length(refspec)) {
146+
refspec <- info$head
147+
}
140148
refspec <- as.character(refspec)
141-
if (isTRUE(force)) refspec <- sub("^\\+?", "+", refspec)
149+
if (isTRUE(force)) {
150+
refspec <- sub("^\\+?", "+", refspec)
151+
}
142152

143153
host <- remote_to_host(repo, remote)
144154
key_cb <- make_key_cb(ssh_key, host = host, password = password)
145155
cred_cb <- make_cred_cb(password = password, verbose = verbose)
146156

147157
.Call(R_git_remote_push, repo, remote, refspec, key_cb, cred_cb, verbose)
148-
if (is.null(set_upstream))
158+
if (is.null(set_upstream)) {
149159
set_upstream <- isTRUE(is.na(info$upstream)) && !isTRUE(info$bare)
160+
}
150161

151162
if (isTRUE(set_upstream)) {
152163
git_branch_set_upstream(paste0(remote, "/", info$shorthand), repo = repo)
@@ -207,7 +218,9 @@ git_clone <- function(
207218
verbose = interactive()
208219
) {
209220
stopifnot(is.character(url))
210-
if (!length(path)) path <- file.path(getwd(), basename(url))
221+
if (!length(path)) {
222+
path <- file.path(getwd(), basename(url))
223+
}
211224
stopifnot(is.character(path))
212225
stopifnot(is.null(branch) || is.character(branch))
213226
verbose <- as.logical(verbose)
@@ -238,16 +251,19 @@ git_pull <- function(remote = NULL, rebase = FALSE, ..., repo = '.') {
238251
repo <- git_open(repo)
239252
info <- git_info(repo)
240253
branch <- info$shorthand
241-
if (branch == "HEAD") stop("Repository is currently in a detached head state")
254+
if (branch == "HEAD") {
255+
stop("Repository is currently in a detached head state")
256+
}
242257

243258
upstream <- if (length(remote) && nchar(remote)) {
244259
paste0(remote, '/', branch)
245260
} else {
246261
info$upstream
247262
}
248263

249-
if (!length(upstream) || is.na(upstream) || !nchar(upstream))
264+
if (!length(upstream) || is.na(upstream) || !nchar(upstream)) {
250265
stop("No upstream configured for current branch, please specify a remote")
266+
}
251267

252268
if (grepl(".*/pr/\\d+$", upstream)) {
253269
pr <- utils::tail(strsplit(upstream, '/pr/', fixed = TRUE)[[1]], 1)
@@ -257,13 +273,15 @@ git_pull <- function(remote = NULL, rebase = FALSE, ..., repo = '.') {
257273
inform("Local upstream, skipping fetch")
258274
} else {
259275
git_fetch(remote, ..., repo = repo)
260-
if (!git_branch_exists(upstream, local = FALSE, repo = repo))
276+
if (!git_branch_exists(upstream, local = FALSE, repo = repo)) {
261277
stop("Failed to fetch upstream branch: ", upstream)
278+
}
262279
}
263280
if (isTRUE(rebase)) {
264281
rebase_df <- git_rebase_list(upstream = upstream, repo = repo)
265-
if (any(rebase_df$conflicts))
282+
if (any(rebase_df$conflicts)) {
266283
stop("Found conflicts, rebase not possible. Retry with rebase = FALSE")
284+
}
267285
git_rebase_commit(upstream = upstream, repo = repo)
268286
} else {
269287
git_merge(upstream, repo = repo)

R/init.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
config$config.home
2020
)
2121
}
22-
if (length(config$config.system) && nchar(config$config.system))
22+
if (length(config$config.system) && nchar(config$config.system)) {
2323
packageStartupInform(paste0("System config: ", config$config.system))
24+
}
2425
try({
2526
settings <- git_config_global()
2627
name <- subset(settings, name == 'user.name')$value
@@ -43,7 +44,9 @@
4344
certpath <- find_cert_dir()
4445
if (length(certpath)) {
4546
cafile <- file.path(dirname(certpath), 'cert.pem')
46-
if (!file.exists(cafile)) cafile <- NULL
47+
if (!file.exists(cafile)) {
48+
cafile <- NULL
49+
}
4750
set_cert_locations(cafile, certpath)
4851
} else {
4952
warning("Unable to find directory with certificates", immediate. = TRUE)
@@ -56,8 +59,7 @@
5659
{
5760
getNamespace('tibble')
5861
},
59-
error = function(e) {
60-
}
62+
error = function(e) {}
6163
)
6264
}
6365

R/merge.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ git_merge <- function(ref, commit = TRUE, squash = FALSE, repo = '.') {
6969
git_merge_stage_only <- function(ref, squash = FALSE, repo = '.') {
7070
repo <- git_open(repo)
7171
success <- .Call(R_git_merge_stage, repo, ref)
72-
if (isTRUE(squash))
72+
if (isTRUE(squash)) {
7373
# This turns it in a regular commit
7474
git_merge_cleanup(repo = repo)
75+
}
7576
return(success)
7677
}
7778

R/pr.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#' pull requests.
1313
git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.') {
1414
pr <- as.character(pr)
15-
if (!length(remote)) remote <- git_info(repo)$remote
15+
if (!length(remote)) {
16+
remote <- git_info(repo)$remote
17+
}
1618
local_branch <- sprintf("pr/%s", pr)
1719
remote_branch <- sprintf("%s/pr/%s", remote, pr)
1820
git_fetch_pull_requests(pr = pr, remote = remote, repo = repo)
@@ -30,7 +32,9 @@ git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.') {
3032
#' @rdname github
3133
git_fetch_pull_requests <- function(pr = '*', remote = NULL, repo = '.') {
3234
pr <- as.character(pr)
33-
if (!length(remote)) remote <- git_info(repo)$remote
35+
if (!length(remote)) {
36+
remote <- git_info(repo)$remote
37+
}
3438
refspec <- sprintf('+refs/pull/%s/head:refs/remotes/%s/pr/%s', pr, remote, pr)
3539
git_fetch(remote = remote, refspec = refspec, repo = repo)
3640
invisible(refspec)

R/rebase.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ git_rebase <- function(upstream, commit_changes, repo) {
3737
repo <- git_open(repo)
3838
info <- git_info(repo = repo)
3939
if (!length(upstream)) {
40-
if (!length(info$upstream) || is.na(info$upstream) || !nchar(info$upstream))
40+
if (
41+
!length(info$upstream) || is.na(info$upstream) || !nchar(info$upstream)
42+
) {
4143
stop("No upstream configured for current HEAD")
44+
}
4245
git_fetch(info$remote, repo = repo)
4346
upstream <- info$upstream
4447
}
@@ -107,7 +110,11 @@ git_cherry_pick <- function(commit, repo = '.') {
107110
#' @useDynLib gert R_git_ahead_behind
108111
git_ahead_behind <- function(upstream = NULL, ref = 'HEAD', repo = '.') {
109112
repo <- git_open(repo)
110-
if (!length(upstream)) upstream <- git_info(repo = repo)$upstream
111-
if (!length(upstream)) stop("No upstream set or specified")
113+
if (!length(upstream)) {
114+
upstream <- git_info(repo = repo)$upstream
115+
}
116+
if (!length(upstream)) {
117+
stop("No upstream set or specified")
118+
}
112119
.Call(R_git_ahead_behind, repo, ref, upstream)
113120
}

R/remotes.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ git_remote_remove <- function(remote, repo = '.') {
4545
git_remote_info <- function(remote = NULL, repo = '.') {
4646
repo <- git_open(repo)
4747
remote <- as.character(remote)
48-
if (!length(remote)) remote <- git_info(repo = repo)$remote
48+
if (!length(remote)) {
49+
remote <- git_info(repo = repo)$remote
50+
}
4951
.Call(R_git_remote_info, repo, remote)
5052
}
5153

@@ -55,7 +57,9 @@ git_remote_info <- function(remote = NULL, repo = '.') {
5557
git_remote_set_url <- function(url, remote = NULL, repo = '.') {
5658
repo <- git_open(repo)
5759
name <- as.character(remote)
58-
if (!length(remote)) remote <- git_info(repo = repo)$remote
60+
if (!length(remote)) {
61+
remote <- git_info(repo = repo)$remote
62+
}
5963
url <- as.character(url)
6064
.Call(R_git_remote_set_url, repo, remote, url)
6165
invisible()
@@ -67,7 +71,9 @@ git_remote_set_url <- function(url, remote = NULL, repo = '.') {
6771
git_remote_set_pushurl <- function(url, remote = NULL, repo = '.') {
6872
repo <- git_open(repo)
6973
remote <- as.character(remote)
70-
if (!length(remote)) remote <- git_info(repo = repo)$remote
74+
if (!length(remote)) {
75+
remote <- git_info(repo = repo)$remote
76+
}
7177
url <- as.character(url)
7278
.Call(R_git_remote_set_pushurl, repo, remote, url)
7379
invisible()
@@ -79,15 +85,19 @@ git_remote_set_pushurl <- function(url, remote = NULL, repo = '.') {
7985
git_remote_refspecs <- function(remote = NULL, repo = '.') {
8086
repo <- git_open(repo)
8187
remote <- as.character(remote)
82-
if (!length(remote)) remote <- git_info(repo = repo)$remote
88+
if (!length(remote)) {
89+
remote <- git_info(repo = repo)$remote
90+
}
8391
.Call(R_git_remote_refspecs, repo, remote)
8492
}
8593

8694
#' @useDynLib gert R_git_remote_add_fetch
8795
git_remote_add_fetch <- function(refspec, remote = NULL, repo = '.') {
8896
repo <- git_open(repo)
8997
remote <- as.character(remote)
90-
if (!length(remote)) remote <- git_info(repo = repo)$remote
98+
if (!length(remote)) {
99+
remote <- git_info(repo = repo)$remote
100+
}
91101
refspec <- as.character(refspec)
92102
.Call(R_git_remote_add_fetch, repo, remote, refspec)
93103
}

0 commit comments

Comments
 (0)