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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
^LICENSE\.md$
^[\.]?air\.toml$
^\.vscode$
^[.]?air[.]toml$
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
36 changes: 27 additions & 9 deletions R/git-auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ gitcreds <- local({
check_for_git()
out <- git_run(c("config", "--get-all", "credential.helper"))
clear <- rev(which(out == ""))
if (length(clear)) out <- out[-(1:clear[1])]
if (length(clear)) {
out <- out[-(1:clear[1])]
}
out
}

Expand Down Expand Up @@ -228,7 +230,9 @@ gitcreds <- local({
}
if (val == "FAIL" || grepl("^FAIL:", val)) {
class <- strsplit(val, ":", fixed = TRUE)[[1]][2]
if (is.na(class)) class <- "gitcreds_no_credentials"
if (is.na(class)) {
class <- "gitcreds_no_credentials"
}
throw(new_error(class))
}

Expand Down Expand Up @@ -438,8 +442,12 @@ gitcreds <- local({
repeat {
ch <- utils::menu(title = "-> What would you like to do?", choices)

if (ch == 1) return(FALSE)
if (ch == 2) return(TRUE)
if (ch == 1) {
return(FALSE)
}
if (ch == 2) {
return(TRUE)
}

msg("\nCurrent password: ", current$password, "\n\n")
}
Expand Down Expand Up @@ -530,7 +538,9 @@ gitcreds <- local({
}

gitcreds_username_for_url <- function(url) {
if (is.null(url)) return(NULL)
if (is.null(url)) {
return(NULL)
}
tryCatch(
git_run(c(
"config",
Expand Down Expand Up @@ -591,10 +601,14 @@ gitcreds <- local({
}

new_error <- function(class, ..., message = "", call. = TRUE, domain = NULL) {
if (message == "") message <- gitcred_errors()[[class]]
if (message == "") {
message <- gitcred_errors()[[class]]
}
message <- .makeMessage(message, domain = domain)
cond <- list(message = message, ...)
if (call.) cond$call <- sys.call(-1)
if (call.) {
cond$call <- sys.call(-1)
}
class(cond) <- c(class, "gitcreds_error", "error", "condition")
cond
}
Expand All @@ -612,10 +626,14 @@ gitcreds <- local({
call. = TRUE,
domain = NULL
) {
if (message == "") message <- gitcred_errors()[[class]]
if (message == "") {
message <- gitcred_errors()[[class]]
}
message <- .makeMessage(message, domain = domain)
cond <- list(message = message, ...)
if (call.) cond$call <- sys.call(-1)
if (call.) {
cond$call <- sys.call(-1)
}
class(cond) <- c(class, "gitcreds_warning", "warning", "condition")
cond
}
Expand Down
28 changes: 21 additions & 7 deletions R/list-creds.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ gitcreds_list <- function(
host <- NULL
if (!is.null(url)) {
purl <- gitcreds$parse_url(url)
if (!is.na(purl$host)) host <- purl$host
if (!is.na(purl$host)) {
host <- purl$host
}
if (!is.na(purl$protocol)) protocol <- purl$protocol
}
protocol <- protocol %||% "https"
Expand Down Expand Up @@ -218,9 +220,15 @@ gitcreds_list_manager_core_macos <- function(url, host, protocol) {
}

is_manager_core_macos_item <- function(it, protocol, host) {
if (is.null(it$attributes$service)) return(FALSE)
if (!grepl("^git:", it$attributes$service)) return(FALSE)
if (is.null(host)) return(TRUE)
if (is.null(it$attributes$service)) {
return(FALSE)
}
if (!grepl("^git:", it$attributes$service)) {
return(FALSE)
}
if (is.null(host)) {
return(TRUE)
}
iturl <- sub("^git:", "", it$attributes$service)
piturl <- gitcreds$parse_url(iturl)
!is.na(piturl$host) &&
Expand All @@ -245,10 +253,16 @@ gitcreds_list_manager_core_win <- function(url, host, protocol) {
}

is_manager_core_win_item <- function(it, protocol, host) {
if (it$type != "generic") return(FALSE)
if (!grepl("^git:", it$target_name)) return(FALSE)
if (it$type != "generic") {
return(FALSE)
}
if (!grepl("^git:", it$target_name)) {
return(FALSE)
}
iturl <- sub("^git:", "", it$target_name)
if (is.null(host)) return(TRUE)
if (is.null(host)) {
return(TRUE)
}
piturl <- gitcreds$parse_url(iturl)
!is.na(piturl$host) &&
piturl$host == host &&
Expand Down
2 changes: 1 addition & 1 deletion man/gitcreds-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ is_ci <- function() {
}

gc_test_that <- function(desc, code, os = NULL, helpers = NULL) {
if (!is_ci()) return()
if (!is_ci()) {
return()
}
if (!is.null(os)) {
if (!gitcreds$get_os() %in% os) return()
}
Expand Down Expand Up @@ -187,13 +189,17 @@ isFALSE <- function(x) {
is_false_check_env_var <- function(x, default = "") {
# like utils:::str2logical
val <- Sys.getenv(x, default)
if (isFALSE(as.logical(val))) return(TRUE)
if (isFALSE(as.logical(val))) {
return(TRUE)
}
tolower(val) %in% c("0", "no")
}

# Only skip if _R_CHECK_FORCE_SUGGESTS_ is false

skip_if_not_installed <- function(pkg) {
if (!is_false_check_env_var("_R_CHECK_FORCE_SUGGESTS_")) return()
if (!is_false_check_env_var("_R_CHECK_FORCE_SUGGESTS_")) {
return()
}
testthat::skip_if_not_installed(pkg)
}
4 changes: 3 additions & 1 deletion tests/testthat/test-gitcreds-list.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ gc_test_that(
os = "windows",
helper = "manager-core",
{
if (packageVersion("oskeyring") <= "0.1.0") skip("Needs newer oskeyring")
if (packageVersion("oskeyring") <= "0.1.0") {
skip("Needs newer oskeyring")
}

# needs oskeyring
fun <- function() {
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-standalone.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ test_that("gitcreds is standalone", {
objs <- ls(stenv, all.names = TRUE)
funs <- Filter(function(x) is.function(stenv[[x]]), objs)
funobjs <- mget(funs, stenv)
for (f in funobjs) expect_identical(environmentName(topenv(f)), "base")
for (f in funobjs) {
expect_identical(environmentName(topenv(f)), "base")
}

skip_if_not_installed("codetools")
expect_message(
Expand Down
Loading