diff --git a/R/archive.R b/R/archive.R index c55fba0f..0ef1da97 100644 --- a/R/archive.R +++ b/R/archive.R @@ -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() diff --git a/R/branch.R b/R/branch.R index 7034ba5b..6e4c25f8 100644 --- a/R/branch.R +++ b/R/branch.R @@ -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) } @@ -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) } diff --git a/R/commit.R b/R/commit.R index c5d2ba1c..dabf3e8f 100644 --- a/R/commit.R +++ b/R/commit.R @@ -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) } @@ -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, @@ -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) } @@ -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") + } } diff --git a/R/errors.R b/R/errors.R index af0f31f5..d4a1047f 100644 --- a/R/errors.R +++ b/R/errors.R @@ -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") } diff --git a/R/fetch.R b/R/fetch.R index f2531a93..b5086546 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -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))) { @@ -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))) { @@ -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) @@ -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) @@ -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) @@ -238,7 +251,9 @@ 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) @@ -246,8 +261,9 @@ git_pull <- function(remote = NULL, rebase = FALSE, ..., repo = '.') { 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) @@ -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) diff --git a/R/init.R b/R/init.R index c01de7be..6a5e3ba6 100644 --- a/R/init.R +++ b/R/init.R @@ -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 @@ -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) @@ -56,8 +59,7 @@ { getNamespace('tibble') }, - error = function(e) { - } + error = function(e) {} ) } diff --git a/R/merge.R b/R/merge.R index c80db478..406c3d92 100644 --- a/R/merge.R +++ b/R/merge.R @@ -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) } diff --git a/R/pr.R b/R/pr.R index 07f9c03e..5da3c437 100644 --- a/R/pr.R +++ b/R/pr.R @@ -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) @@ -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) diff --git a/R/rebase.R b/R/rebase.R index f1b4f43b..d164ac83 100644 --- a/R/rebase.R +++ b/R/rebase.R @@ -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 } @@ -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) } diff --git a/R/remotes.R b/R/remotes.R index 2553eca9..03c00e5d 100644 --- a/R/remotes.R +++ b/R/remotes.R @@ -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) } @@ -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() @@ -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() @@ -79,7 +85,9 @@ 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) } @@ -87,7 +95,9 @@ git_remote_refspecs <- function(remote = NULL, repo = '.') { 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) } diff --git a/R/signature.R b/R/signature.R index 28cffcec..86d2adc6 100644 --- a/R/signature.R +++ b/R/signature.R @@ -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) { diff --git a/R/submodules.R b/R/submodules.R index 860ecfea..4498f035 100644 --- a/R/submodules.R +++ b/R/submodules.R @@ -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) } diff --git a/tests/spelling.R b/tests/spelling.R index 6713838f..c597a129 100644 --- a/tests/spelling.R +++ b/tests/spelling.R @@ -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 + ) +} diff --git a/tests/testthat/test-auth.R b/tests/testthat/test-auth.R index aea39de3..396fb5a1 100644 --- a/tests/testthat/test-auth.R +++ b/tests/testthat/test-auth.R @@ -1,9 +1,14 @@ # Even for public repos, Github only allows keys that it knows. test_that("public ssh remotes with random key", { - skip_if_offline('github.com') #Also skips on_cran + skip_if_offline('github.com') #Also skips on_cran remote <- 'git@github.com:jeroen/webp.git' target <- file.path(tempdir(), basename(remote)) - repo <- git_clone(remote, path = target, ssh_key = 'ecdsa.key', password = 'testingjerry') + repo <- git_clone( + remote, + path = target, + ssh_key = 'ecdsa.key', + password = 'testingjerry' + ) expect_true(file.exists(file.path(target, 'DESCRIPTION'))) }) @@ -13,17 +18,34 @@ test_that("private ssh remotes with key", { remote <- 'git@github.com:jeroenooms/testprivate.git' # Test errors - expect_error(git_clone(remote, path = tempfile(), ssh_key = 'doesnotexist'), 'load key', class = 'GIT_EAUTH') - expect_error(git_clone(remote, path = tempfile(), ssh_key = 'pat.bin'), 'load key', class = 'GIT_EAUTH') + expect_error( + git_clone(remote, path = tempfile(), ssh_key = 'doesnotexist'), + 'load key', + class = 'GIT_EAUTH' + ) + expect_error( + git_clone(remote, path = tempfile(), ssh_key = 'pat.bin'), + 'load key', + class = 'GIT_EAUTH' + ) # Also test password as a callback function - for(keyfile in c("ecdsa.key", "rsa3072.key", "ed25519.key")){ + for (keyfile in c("ecdsa.key", "rsa3072.key", "ed25519.key")) { target <- tempfile() - repo <- git_clone(remote, path = target, ssh_key = keyfile, password = function(...){ 'testingjerry'}) + repo <- git_clone( + remote, + path = target, + ssh_key = keyfile, + password = function(...) { + 'testingjerry' + } + ) expect_true(file.exists(file.path(target, 'hello'))) # Test ls-remote auth - git_remote_ls(repo = target, ssh_key = keyfile, password = function(...){ 'testingjerry'}) + git_remote_ls(repo = target, ssh_key = keyfile, password = function(...) { + 'testingjerry' + }) } }) @@ -37,19 +59,34 @@ test_that("HTTP user/pass auth", { enc <- readBin('pat.bin', raw(), 1e3) dec <- openssl::rsa_decrypt(enc, 'key.pem', password = 'testingjerry') target2 <- file.path(tempdir(), 'testprivate2') - repo <- git_clone('https://testingjerry@github.com/jeroenooms/testprivate', - path = target2, password = rawToChar(dec)) + repo <- git_clone( + 'https://testingjerry@github.com/jeroenooms/testprivate', + path = target2, + password = rawToChar(dec) + ) expect_true(file.exists(file.path(target2, 'hello'))) # Test with password in URL target3 <- file.path(tempdir(), 'testprivate3') - repo <- git_clone(sprintf('https://testingjerry:%s@github.com/jeroenooms/testprivate', - rawToChar(dec)), path = target3) + repo <- git_clone( + sprintf( + 'https://testingjerry:%s@github.com/jeroenooms/testprivate', + rawToChar(dec) + ), + path = target3 + ) expect_true(file.exists(file.path(target3, 'hello'))) # Test that repo is private - expect_error(git_clone('https://github.com/jeroenooms/testprivate', - password = "bla", path = tempfile()), 'Authentication', class = 'GIT_EAUTH') + expect_error( + git_clone( + 'https://github.com/jeroenooms/testprivate', + password = "bla", + path = tempfile() + ), + 'Authentication', + class = 'GIT_EAUTH' + ) # Test with PAT Sys.setenv(GITHUB_PAT = rawToChar(dec)) @@ -63,7 +100,10 @@ test_that("HTTP user/pass auth", { # Try with user in URL target5 <- file.path(tempdir(), 'testprivate5') - repo <- git_clone('https://nobody@github.com/jeroenooms/testprivate', path = target5) + repo <- git_clone( + 'https://nobody@github.com/jeroenooms/testprivate', + path = target5 + ) expect_true(file.exists(file.path(target5, 'hello'))) heads <- git_remote_ls(repo = repo) expect_is(heads, 'data.frame') diff --git a/tests/testthat/test-clone.R b/tests/testthat/test-clone.R index f8ae8d63..972da854 100644 --- a/tests/testthat/test-clone.R +++ b/tests/testthat/test-clone.R @@ -4,7 +4,10 @@ test_that("cloning repositories works", { repo <- git_clone('https://github.com/r-lib/gert', path = path) expect_true(file.exists(file.path(path, 'DESCRIPTION'))) info <- git_info(repo) - default_head <- git_remote_ls('https://github.com/r-lib/gert', repo = repo)$symref[1] + default_head <- git_remote_ls( + 'https://github.com/r-lib/gert', + repo = repo + )$symref[1] default_branch <- basename(default_head) expect_equal(info$head, default_head) expect_equal(info$shorthand, default_branch) @@ -15,7 +18,10 @@ test_that("cloning repositories works", { expect_is(git_log(repo = repo), 'data.frame') heads <- git_remote_ls(repo = repo) expect_is(heads, 'data.frame') - expect_equal(git_remote_info(repo = repo)$head, paste0("refs/remotes/origin/", default_branch)) + expect_equal( + git_remote_info(repo = repo)$head, + paste0("refs/remotes/origin/", default_branch) + ) # Test remotes remotes <- git_remote_list(repo) @@ -24,6 +30,6 @@ test_that("cloning repositories works", { # Test archive expect_equal(git_archive_zip(repo = repo), 'gert.zip') - expect_equal(zip::zip_list('gert.zip')$filename, git_ls(repo=repo)$path) + expect_equal(zip::zip_list('gert.zip')$filename, git_ls(repo = repo)$path) unlink('gert.zip') }) diff --git a/tests/testthat/test-commit.R b/tests/testthat/test-commit.R index 03fba72d..c334ca8b 100644 --- a/tests/testthat/test-commit.R +++ b/tests/testthat/test-commit.R @@ -10,7 +10,7 @@ test_that("creating signatures", { expect_equal(sigdata$email, email) expect_lt(difftime(sigdata$time, now, 'secs'), 1) - yesterday <- now - 24*60*60 + yesterday <- now - 24 * 60 * 60 sig <- git_signature(name, email, time = yesterday) sigdata <- git_signature_parse(sig) expect_equal(sigdata$name, name) @@ -51,7 +51,7 @@ test_that("creating a commit", { # Another commit before that write.csv(iris, file.path(repo, 'iris.csv')) git_add("iris.csv", repo = repo) - timestamp <- round(Sys.time() - 48*60*60) + timestamp <- round(Sys.time() - 48 * 60 * 60) sig2 <- git_signature('nobody', 'nobody@gmail.com', time = timestamp) git_commit("Added iris.csv also", author = sig2, repo = repo) @@ -130,8 +130,11 @@ test_that("status reports a conflicted file", { rebase_info <- git_rebase_list("my-branch", repo = repo) expect_equal(rebase_info$type, rep("pick", 3)) expect_equal(rebase_info$commit, rev(head(git_log(repo = repo), -1)$commit)) - expect_equal(rebase_info$conflicts, c(T,T,F)) - expect_error(git_rebase_commit("my-branch", repo = repo), class = "GIT_EMERGECONFLICT") + expect_equal(rebase_info$conflicts, c(T, T, F)) + expect_error( + git_rebase_commit("my-branch", repo = repo), + class = "GIT_EMERGECONFLICT" + ) expect_error(git_branch_fast_forward("my-branch", repo = repo)) # Merge returns FALSE due to conflicts diff --git a/tests/testthat/test-ignore.R b/tests/testthat/test-ignore.R index 32dc85ae..afefd86b 100644 --- a/tests/testthat/test-ignore.R +++ b/tests/testthat/test-ignore.R @@ -1,17 +1,22 @@ test_that("can check that files are ignored", { repo <- git_init(tempfile("gert-tests-open")) - writeLines(c( - "*.so", - "!foo.so", - "some-file", - "directory/"), - file.path(repo, ".gitignore")) + writeLines( + c( + "*.so", + "!foo.so", + "some-file", + "directory/" + ), + file.path(repo, ".gitignore") + ) expect_true(git_ignore_path_is_ignored("x.so", repo)) expect_false(git_ignore_path_is_ignored("foo.so", repo)) expect_true(git_ignore_path_is_ignored("some-file", repo)) expect_false(git_ignore_path_is_ignored("some-file.txt", repo)) expect_true(git_ignore_path_is_ignored("directory/a", repo)) - expect_equal(git_ignore_path_is_ignored(c("x.so", "foo.so"), repo), - c(TRUE, FALSE)) + expect_equal( + git_ignore_path_is_ignored(c("x.so", "foo.so"), repo), + c(TRUE, FALSE) + ) expect_equal(git_ignore_path_is_ignored(character(), repo), logical()) }) diff --git a/tests/testthat/test-merge.R b/tests/testthat/test-merge.R index 06785857..2c469bb9 100644 --- a/tests/testthat/test-merge.R +++ b/tests/testthat/test-merge.R @@ -5,7 +5,7 @@ test_that("merge analysis works", { on.exit(setwd(oldwd), add = TRUE) setwd(repo) configure_local_user() - for(i in 1:5){ + for (i in 1:5) { writeLines(paste('Blabla', i), "test.txt") git_add("test.txt") git_commit(paste("This is commit number:", i)) @@ -15,7 +15,7 @@ test_that("merge analysis works", { first_commit <- tail(master_log$commit, 1) git_branch_create('new', first_commit) git_branch_checkout('new') - expect_equal(git_log()$commit, tail(master_log,1)$commit) + expect_equal(git_log()$commit, tail(master_log, 1)$commit) expect_equal(git_merge_analysis(main), 'fastforward') # Expect no merge commit (ffwd) @@ -42,4 +42,3 @@ test_that("merge analysis works", { git_merge(main) expect_equal(git_log(), newlog) }) - diff --git a/tests/testthat/test-rebase.R b/tests/testthat/test-rebase.R index 781d7a4a..37dab133 100644 --- a/tests/testthat/test-rebase.R +++ b/tests/testthat/test-rebase.R @@ -1,7 +1,9 @@ test_that("rebasing things", { skip_if_offline('github.com') repo <- file.path(tempdir(), 'gert') - if(!file.exists(repo)) git_clone('https://github.com/r-lib/gert', path = repo) + if (!file.exists(repo)) { + git_clone('https://github.com/r-lib/gert', path = repo) + } git_branch_create('backup', checkout = FALSE, repo = repo) # Original log @@ -9,31 +11,65 @@ test_that("rebasing things", { # Drop some commits, and fast-forward them back git_reset_hard('HEAD~5', repo = repo) - expect_equal(git_log(max = 5, repo = repo)$commit, utils::tail(orig$commit, 5)) - expect_equal(git_ahead_behind(repo = repo), list(ahead = 0, behind = 5, - local = git_commit_id(repo = repo), upstream = git_commit_id('origin/HEAD', repo = repo))) + expect_equal( + git_log(max = 5, repo = repo)$commit, + utils::tail(orig$commit, 5) + ) + expect_equal( + git_ahead_behind(repo = repo), + list( + ahead = 0, + behind = 5, + local = git_commit_id(repo = repo), + upstream = git_commit_id('origin/HEAD', repo = repo) + ) + ) git_pull(repo = repo) expect_equal(orig, git_log(max = 10, repo = repo)) # Same with rebase git_reset_hard('HEAD~5', repo = repo) - expect_equal(git_log(max = 5, repo = repo)$commit, utils::tail(orig$commit, 5)) - expect_equal(git_ahead_behind(repo = repo), list(ahead = 0, behind = 5, - local = git_commit_id(repo = repo), upstream = git_commit_id('origin/HEAD', repo = repo))) + expect_equal( + git_log(max = 5, repo = repo)$commit, + utils::tail(orig$commit, 5) + ) + expect_equal( + git_ahead_behind(repo = repo), + list( + ahead = 0, + behind = 5, + local = git_commit_id(repo = repo), + upstream = git_commit_id('origin/HEAD', repo = repo) + ) + ) git_pull(rebase = TRUE, repo = repo) expect_equal(orig, git_log(max = 10, repo = repo)) # Now rebase a commit git_reset_hard('HEAD~5', repo = repo) - expect_equal(git_log(max = 5, repo = repo)$commit, utils::tail(orig$commit, 5)) + expect_equal( + git_log(max = 5, repo = repo)$commit, + utils::tail(orig$commit, 5) + ) writeLines("some random change", file.path(repo, 'randomfile.txt')) git_add(".", repo = repo) - commit_id <- git_commit("Added a local change", repo = repo, author = "Jerry ") + commit_id <- git_commit( + "Added a local change", + repo = repo, + author = "Jerry " + ) commit_msg <- git_commit_info(commit_id, repo = repo)$message # We are 1 ahead and 5 behind - expect_equal(git_ahead_behind(repo = repo), list(ahead = 1, behind = 5, - local = git_commit_id(repo = repo), upstream = git_commit_id('origin/HEAD', repo = repo))) + expect_equal( + git_ahead_behind(repo = repo), + list( + ahead = 1, + behind = 5, + local = git_commit_id(repo = repo), + upstream = git_commit_id('origin/HEAD', repo = repo) + ) + ) # Confirm that we cannot fast forward upstream <- git_info(repo = repo)$upstream @@ -46,11 +82,21 @@ test_that("rebasing things", { newlog <- git_log(max = 11, repo = repo) expect_equal(c(commit_msg, orig$message), newlog$message) expect_equal(orig$commit, newlog$commit[-1]) - expect_equal(git_ahead_behind(repo = repo), list(ahead = 1, behind = 0, - local = git_commit_id(repo = repo), upstream = git_commit_id('origin/HEAD', repo = repo))) + expect_equal( + git_ahead_behind(repo = repo), + list( + ahead = 1, + behind = 0, + local = git_commit_id(repo = repo), + upstream = git_commit_id('origin/HEAD', repo = repo) + ) + ) # Check that patch matches - expect_equal(git_diff(commit_id, repo = repo), git_diff(newlog$commit[1], repo = repo)) + expect_equal( + git_diff(commit_id, repo = repo), + git_diff(newlog$commit[1], repo = repo) + ) # Merge changes into another branch main <- git_info(repo = repo)$shorthand @@ -69,18 +115,26 @@ test_that("cherry-picking things", { gert::git_init(path = repo) writeLines("hello", file.path(repo, 'hello.txt')) git_add('hello.txt', repo = repo) - first_commit <- git_commit("First commit", author = "jeroen ", repo = repo) + first_commit <- git_commit( + "First commit", + author = "jeroen ", + repo = repo + ) # Create a feature branch with a new commit mainbranch <- gert::git_branch(repo = repo) git_branch_create('feature', repo = repo) write.csv(iris, file.path(repo, 'iris.csv')) git_add('iris.csv', repo = repo) - commit <- git_commit("Added iris.csv file", author = "maelle ", repo = repo) + commit <- git_commit( + "Added iris.csv file", + author = "maelle ", + repo = repo + ) # Cherry pick the commit onto main git_branch_checkout(mainbranch, repo = repo) - expect_equal(git_log(repo=repo)$commit, first_commit) + expect_equal(git_log(repo = repo)$commit, first_commit) short_commit <- substr(commit, 1, 7) expect_equal(git_cherry_pick(short_commit, repo = repo), commit) expect_length(git_log(repo = repo)$commit, 2) diff --git a/tests/testthat/test-remotes.R b/tests/testthat/test-remotes.R index 2b5cf116..6c656760 100644 --- a/tests/testthat/test-remotes.R +++ b/tests/testthat/test-remotes.R @@ -1,4 +1,4 @@ -test_that("remotes from new repo",{ +test_that("remotes from new repo", { skip_if_offline('github.com') repo <- git_init(tempfile("gert-tests-remote")) on.exit(unlink(repo, recursive = TRUE)) @@ -6,11 +6,26 @@ test_that("remotes from new repo",{ expect_error(git_remote_info(repo = repo)) expect_error(git_remote_refspecs(repo = repo)) expect_error(git_remote_set_url('https://github.com/foo/bar', repo = repo)) - expect_error(git_remote_set_pushurl('https://github.com/foo/bar', repo = repo)) - expect_equal(git_remote_add('https://github.com/jeroen/webp', name = 'jeroen', repo = repo), 'jeroen') + expect_error(git_remote_set_pushurl( + 'https://github.com/foo/bar', + repo = repo + )) + expect_equal( + git_remote_add( + 'https://github.com/jeroen/webp', + name = 'jeroen', + repo = repo + ), + 'jeroen' + ) git_fetch('jeroen', 'master', repo = repo) git_branch_create('master', 'jeroen/master', repo = repo) - git_branch_create('testje', git_commit_id('jeroen/master', repo = repo), checkout = FALSE, repo = repo) + git_branch_create( + 'testje', + git_commit_id('jeroen/master', repo = repo), + checkout = FALSE, + repo = repo + ) git_remote_set_pushurl('https://github.com/foo/baz', repo = repo) info <- git_remote_info(repo = repo) expect_equal(info$name, 'jeroen') @@ -25,7 +40,9 @@ test_that("remotes from new repo",{ test_that("remotes after clone", { skip_if_offline('github.com') repo <- file.path(tempdir(), 'gert') - if(!file.exists(repo)) git_clone('https://github.com/r-lib/gert', path = repo) + if (!file.exists(repo)) { + git_clone('https://github.com/r-lib/gert', path = repo) + } info <- git_remote_info(repo = repo) expect_equal(info$name, 'origin') expect_equal(info$url, "https://github.com/r-lib/gert") @@ -36,9 +53,22 @@ test_that("remotes after clone", { expect_equal(remotelist$name, 'origin') expect_equal(remotelist$url, 'https://github.com/r-lib/gert') expect_error(git_remote_add('https://github.com/jeroen/gert', repo = repo)) - expect_equal(git_remote_add('https://github.com/jeroen/gert', name = 'myfork', repo = repo), 'myfork') + expect_equal( + git_remote_add( + 'https://github.com/jeroen/gert', + name = 'myfork', + repo = repo + ), + 'myfork' + ) remotelist <- git_remote_list(repo = repo) expect_equal(sort(remotelist$name), c("myfork", 'origin')) - expect_equal(sort(remotelist$url), c("https://github.com/jeroen/gert", 'https://github.com/r-lib/gert')) - expect_equal(git_remote_refspecs('myfork', repo = repo)$refspec, '+refs/heads/*:refs/remotes/myfork/*') + expect_equal( + sort(remotelist$url), + c("https://github.com/jeroen/gert", 'https://github.com/r-lib/gert') + ) + expect_equal( + git_remote_refspecs('myfork', repo = repo)$refspec, + '+refs/heads/*:refs/remotes/myfork/*' + ) }) diff --git a/tools/winlibs.R b/tools/winlibs.R index fe924020..587d871a 100644 --- a/tools/winlibs.R +++ b/tools/winlibs.R @@ -1,10 +1,12 @@ -if(!file.exists('clone.o') && !file.exists("../.deps/libgit2/include/git2.h")){ +if ( + !file.exists('clone.o') && !file.exists("../.deps/libgit2/include/git2.h") +) { unlink("../.deps", recursive = TRUE) - url <- if(grepl("aarch", R.version$platform)){ + url <- if (grepl("aarch", R.version$platform)) { "https://github.com/r-windows/bundles/releases/download/libgit2-1.9.1/libgit2-1.9.1-clang-aarch64.tar.xz" - } else if(grepl("clang", Sys.getenv('R_COMPILED_BY'))){ + } else if (grepl("clang", Sys.getenv('R_COMPILED_BY'))) { "https://github.com/r-windows/bundles/releases/download/libgit2-1.9.1/libgit2-1.9.1-clang-x86_64.tar.xz" - } else if(getRversion() >= "4.2") { + } else if (getRversion() >= "4.2") { "https://github.com/r-windows/bundles/releases/download/libgit2-1.9.1/libgit2-1.9.1-ucrt-x86_64.tar.xz" } else { "https://github.com/rwinlib/libgit2/archive/v1.7.1.tar.gz"