Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ git_archive_internal <- function(outfile, repo) {
git_stash_save(repo = repo)
on.exit(git_stash_pop(repo = repo))
},
GIT_ENOTFOUND = function(e) {
}
GIT_ENOTFOUND = function(e) {}
)
files <- git_ls(repo = repo)$path
wd <- getwd()
Expand Down
6 changes: 4 additions & 2 deletions R/branch.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ git_branch_move <- function(branch, new_branch, force = FALSE, repo = '.') {
#' @rdname git_branch
git_branch_fast_forward <- function(ref, repo = '.') {
analysis <- git_merge_analysis(ref = ref, repo = repo)
if (analysis != "fastforward")
if (analysis != "fastforward") {
stop("Branch cannot be fast-forwarded. Use git_merge() instead")
}
git_branch_set_target(ref = ref, repo = repo)
}

Expand All @@ -128,8 +129,9 @@ git_branch_set_upstream <- function(
) {
repo <- git_open(repo)
stopifnot(is.character(upstream))
if (!git_branch_exists(upstream, local = FALSE, repo = repo))
if (!git_branch_exists(upstream, local = FALSE, repo = repo)) {
stop(sprintf("No remote branch found: %s, maybe fetch first?", upstream))
}
.Call(R_git_branch_set_upstream, repo, upstream, branch)
git_repo_path(repo)
}
Expand Down
18 changes: 13 additions & 5 deletions R/commit.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ git_commit <- function(message, author = NULL, committer = NULL, repo = '.') {
}
stopifnot(is.character(message), length(message) == 1)
status <- git_status(repo = repo)
if (!any(status$staged))
if (!any(status$staged)) {
stop("No staged files to commit. Run git_add() to select files.")
}
merge_parents <- git_merge_parent_heads(repo = repo)
.Call(R_git_commit_create, repo, message, author, committer, merge_parents)
}
Expand All @@ -94,10 +95,14 @@ git_commit_all <- function(
changes <- unstaged$file[
unstaged$status %in% c("modified", "renamed", "typechange")
]
if (length(changes)) git_add(changes, repo = repo)
if (length(changes)) {
git_add(changes, repo = repo)
}

deleted <- unstaged$file[unstaged$status == "deleted"]
if (length(deleted)) git_rm(deleted, repo = repo)
if (length(deleted)) {
git_rm(deleted, repo = repo)
}

git_commit(
message = message,
Expand Down Expand Up @@ -209,7 +214,9 @@ git_log <- function(ref = "HEAD", max = 100, after = NULL, repo = ".") {
repo <- git_open(repo)
ref <- as.character(ref)
max <- as.integer(max)
if (length(after)) after <- as.POSIXct(after)
if (length(after)) {
after <- as.POSIXct(after)
}
.Call(R_git_commit_log, repo, ref, max, after)
}

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

assert_string <- function(x) {
if (!is.character(x) || !length(x))
if (!is.character(x) || !length(x)) {
stop("Argument must be a string of length 1")
}
}
4 changes: 3 additions & 1 deletion R/errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ raise_libgit2_error <- function(code, message, where = "", kclass = 0) {

libgit2_error_name <- function(x) {
out <- which(libgit2_error_codes == x)
if (length(out)) return(names(out))
if (length(out)) {
return(names(out))
}
return("UNKNOWN_ERROR_CODE")
}

Expand Down
40 changes: 29 additions & 11 deletions R/fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ git_fetch <- function(
) {
repo <- git_open(repo)
info <- git_info(repo)
if (!length(remote)) remote <- info$remote
if (!length(remote)) {
remote <- info$remote
}
remote <- as.character(remote)
if (!length(remote) || is.na(remote)) {
if (is.na(match("origin", git_remote_list(repo = repo)$name))) {
Expand Down Expand Up @@ -77,7 +79,9 @@ git_remote_ls <- function(
) {
repo <- git_open(repo)
info <- git_info(repo)
if (!length(remote)) remote <- info$remote
if (!length(remote)) {
remote <- info$remote
}
remote <- as.character(remote)
if (!length(remote) || is.na(remote)) {
if (is.na(match("origin", git_remote_list(repo = repo)$name))) {
Expand Down Expand Up @@ -115,7 +119,9 @@ git_push <- function(
info <- git_info(repo)
verbose <- as.logical(verbose)

if (!length(remote)) remote <- info$remote
if (!length(remote)) {
remote <- info$remote
}

remote <- as.character(remote)

Expand All @@ -136,17 +142,22 @@ git_push <- function(
refs <- refs[!grepl("^refs/pull", refs)]
refspec <- paste0(refs, ":", refs)
}
if (!length(refspec)) refspec <- info$head
if (!length(refspec)) {
refspec <- info$head
}
refspec <- as.character(refspec)
if (isTRUE(force)) refspec <- sub("^\\+?", "+", refspec)
if (isTRUE(force)) {
refspec <- sub("^\\+?", "+", refspec)
}

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

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

if (isTRUE(set_upstream)) {
git_branch_set_upstream(paste0(remote, "/", info$shorthand), repo = repo)
Expand Down Expand Up @@ -207,7 +218,9 @@ git_clone <- function(
verbose = interactive()
) {
stopifnot(is.character(url))
if (!length(path)) path <- file.path(getwd(), basename(url))
if (!length(path)) {
path <- file.path(getwd(), basename(url))
}
stopifnot(is.character(path))
stopifnot(is.null(branch) || is.character(branch))
verbose <- as.logical(verbose)
Expand Down Expand Up @@ -238,16 +251,19 @@ git_pull <- function(remote = NULL, rebase = FALSE, ..., repo = '.') {
repo <- git_open(repo)
info <- git_info(repo)
branch <- info$shorthand
if (branch == "HEAD") stop("Repository is currently in a detached head state")
if (branch == "HEAD") {
stop("Repository is currently in a detached head state")
}

upstream <- if (length(remote) && nchar(remote)) {
paste0(remote, '/', branch)
} else {
info$upstream
}

if (!length(upstream) || is.na(upstream) || !nchar(upstream))
if (!length(upstream) || is.na(upstream) || !nchar(upstream)) {
stop("No upstream configured for current branch, please specify a remote")
}

if (grepl(".*/pr/\\d+$", upstream)) {
pr <- utils::tail(strsplit(upstream, '/pr/', fixed = TRUE)[[1]], 1)
Expand All @@ -257,13 +273,15 @@ git_pull <- function(remote = NULL, rebase = FALSE, ..., repo = '.') {
inform("Local upstream, skipping fetch")
} else {
git_fetch(remote, ..., repo = repo)
if (!git_branch_exists(upstream, local = FALSE, repo = repo))
if (!git_branch_exists(upstream, local = FALSE, repo = repo)) {
stop("Failed to fetch upstream branch: ", upstream)
}
}
if (isTRUE(rebase)) {
rebase_df <- git_rebase_list(upstream = upstream, repo = repo)
if (any(rebase_df$conflicts))
if (any(rebase_df$conflicts)) {
stop("Found conflicts, rebase not possible. Retry with rebase = FALSE")
}
git_rebase_commit(upstream = upstream, repo = repo)
} else {
git_merge(upstream, repo = repo)
Expand Down
10 changes: 6 additions & 4 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
config$config.home
)
}
if (length(config$config.system) && nchar(config$config.system))
if (length(config$config.system) && nchar(config$config.system)) {
packageStartupInform(paste0("System config: ", config$config.system))
}
try({
settings <- git_config_global()
name <- subset(settings, name == 'user.name')$value
Expand All @@ -43,7 +44,9 @@
certpath <- find_cert_dir()
if (length(certpath)) {
cafile <- file.path(dirname(certpath), 'cert.pem')
if (!file.exists(cafile)) cafile <- NULL
if (!file.exists(cafile)) {
cafile <- NULL
}
set_cert_locations(cafile, certpath)
} else {
warning("Unable to find directory with certificates", immediate. = TRUE)
Expand All @@ -56,8 +59,7 @@
{
getNamespace('tibble')
},
error = function(e) {
}
error = function(e) {}
)
}

Expand Down
3 changes: 2 additions & 1 deletion R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ git_merge <- function(ref, commit = TRUE, squash = FALSE, repo = '.') {
git_merge_stage_only <- function(ref, squash = FALSE, repo = '.') {
repo <- git_open(repo)
success <- .Call(R_git_merge_stage, repo, ref)
if (isTRUE(squash))
if (isTRUE(squash)) {
# This turns it in a regular commit
git_merge_cleanup(repo = repo)
}
return(success)
}

Expand Down
8 changes: 6 additions & 2 deletions R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#' pull requests.
git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.') {
pr <- as.character(pr)
if (!length(remote)) remote <- git_info(repo)$remote
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)
Expand All @@ -30,7 +32,9 @@ git_checkout_pull_request <- function(pr = 1, remote = NULL, repo = '.') {
#' @rdname github
git_fetch_pull_requests <- function(pr = '*', remote = NULL, repo = '.') {
pr <- as.character(pr)
if (!length(remote)) remote <- git_info(repo)$remote
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)
Expand Down
13 changes: 10 additions & 3 deletions R/rebase.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ git_rebase <- function(upstream, commit_changes, repo) {
repo <- git_open(repo)
info <- git_info(repo = repo)
if (!length(upstream)) {
if (!length(info$upstream) || is.na(info$upstream) || !nchar(info$upstream))
if (
!length(info$upstream) || is.na(info$upstream) || !nchar(info$upstream)
) {
stop("No upstream configured for current HEAD")
}
git_fetch(info$remote, repo = repo)
upstream <- info$upstream
}
Expand Down Expand Up @@ -107,7 +110,11 @@ git_cherry_pick <- function(commit, repo = '.') {
#' @useDynLib gert R_git_ahead_behind
git_ahead_behind <- function(upstream = NULL, ref = 'HEAD', repo = '.') {
repo <- git_open(repo)
if (!length(upstream)) upstream <- git_info(repo = repo)$upstream
if (!length(upstream)) stop("No upstream set or specified")
if (!length(upstream)) {
upstream <- git_info(repo = repo)$upstream
}
if (!length(upstream)) {
stop("No upstream set or specified")
}
.Call(R_git_ahead_behind, repo, ref, upstream)
}
20 changes: 15 additions & 5 deletions R/remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ git_remote_remove <- function(remote, repo = '.') {
git_remote_info <- function(remote = NULL, repo = '.') {
repo <- git_open(repo)
remote <- as.character(remote)
if (!length(remote)) remote <- git_info(repo = repo)$remote
if (!length(remote)) {
remote <- git_info(repo = repo)$remote
}
.Call(R_git_remote_info, repo, remote)
}

Expand All @@ -55,7 +57,9 @@ git_remote_info <- function(remote = NULL, repo = '.') {
git_remote_set_url <- function(url, remote = NULL, repo = '.') {
repo <- git_open(repo)
name <- as.character(remote)
if (!length(remote)) remote <- git_info(repo = repo)$remote
if (!length(remote)) {
remote <- git_info(repo = repo)$remote
}
url <- as.character(url)
.Call(R_git_remote_set_url, repo, remote, url)
invisible()
Expand All @@ -67,7 +71,9 @@ git_remote_set_url <- function(url, remote = NULL, repo = '.') {
git_remote_set_pushurl <- function(url, remote = NULL, repo = '.') {
repo <- git_open(repo)
remote <- as.character(remote)
if (!length(remote)) remote <- git_info(repo = repo)$remote
if (!length(remote)) {
remote <- git_info(repo = repo)$remote
}
url <- as.character(url)
.Call(R_git_remote_set_pushurl, repo, remote, url)
invisible()
Expand All @@ -79,15 +85,19 @@ git_remote_set_pushurl <- function(url, remote = NULL, repo = '.') {
git_remote_refspecs <- function(remote = NULL, repo = '.') {
repo <- git_open(repo)
remote <- as.character(remote)
if (!length(remote)) remote <- git_info(repo = repo)$remote
if (!length(remote)) {
remote <- git_info(repo = repo)$remote
}
.Call(R_git_remote_refspecs, repo, remote)
}

#' @useDynLib gert R_git_remote_add_fetch
git_remote_add_fetch <- function(refspec, remote = NULL, repo = '.') {
repo <- git_open(repo)
remote <- as.character(remote)
if (!length(remote)) remote <- git_info(repo = repo)$remote
if (!length(remote)) {
remote <- git_info(repo = repo)$remote
}
refspec <- as.character(refspec)
.Call(R_git_remote_add_fetch, repo, remote, refspec)
}
4 changes: 3 additions & 1 deletion R/signature.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ offset_to_string <- function(offset) {
hours <- as.integer(offset %/% 60)
mins <- as.integer(offset %% 60)
sprintf('%+03d%02d', hours, mins)
} else ""
} else {
""
}
}

sig_data_to_string <- function(x) {
Expand Down
3 changes: 2 additions & 1 deletion R/submodules.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ git_submodule_set_to <- function(submodule, ref, checkout = TRUE, repo = '.') {
} else if (!is_full_hash(ref)) {
ref <- git_commit_info(ref, repo = I(info$path))$id
}
if (!is_full_hash(ref))
if (!is_full_hash(ref)) {
stop("When checkout = FALSE, parameter ref must be a full hash")
}
.Call(R_git_submodule_set_to, repo, submodule, ref)
}

Expand Down
10 changes: 7 additions & 3 deletions tests/spelling.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
if (requireNamespace('spelling', quietly = TRUE)) {
spelling::spell_check_test(
vignettes = TRUE,
error = FALSE,
skip_on_cran = TRUE
)
}
Loading
Loading