Skip to content

Commit 999bf5a

Browse files
committed
Attempt to fix errors I see on CI
1 parent 3de7fd8 commit 999bf5a

File tree

6 files changed

+53
-59
lines changed

6 files changed

+53
-59
lines changed

R/git-auth.R

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,26 +302,6 @@ gitcreds_env <- function() {
302302
)
303303
}
304304

305-
#' Check if `git` is installed and can run
306-
#'
307-
#' If not installed, a `gitcreds_nogit_error` is thrown.
308-
#'
309-
#' @noRd
310-
#' @return Nothing
311-
312-
check_for_git <- function() {
313-
# This is simpler than Sys.which(), and also less fragile
314-
has_git <- tryCatch({
315-
suppressWarnings(system2(
316-
"git", "--version",
317-
stdout = TRUE, stderr = null_file()
318-
))
319-
TRUE
320-
}, error = function(e) FALSE)
321-
322-
if (!has_git) throw(new_error("gitcreds_nogit_error"))
323-
}
324-
325305
new_gitcreds <- function(...) {
326306
structure(list(...), class = "gitcreds")
327307
}
@@ -371,16 +351,12 @@ has_no_newline <- function(url) {
371351
! grepl("\n", url, fixed = TRUE)
372352
}
373353

374-
null_file <- function() {
375-
if (get_os() == "windows") "nul:" else "/dev/null"
376-
}
377-
378354
`%||%` <- function(l, r) if (is.null(l)) r else l
379355

380356
environment()
381357
})
382358

383-
# FIXME: Moving these functions outside of `local()` to avoid
359+
# Moving these functions outside of `local()` to avoid
384360
# Error in `local_mocked_bindings()`:
385361
# ! Can't find binding for `SOME_FUNCTION`
386362

@@ -835,3 +811,27 @@ gitcreds_set_replace <- function(url, current) {
835811

836812
invisible()
837813
}
814+
815+
#' Check if `git` is installed and can run
816+
#'
817+
#' If not installed, a `gitcreds_nogit_error` is thrown.
818+
#'
819+
#' @noRd
820+
#' @return Nothing
821+
822+
check_for_git <- function() {
823+
# This is simpler than Sys.which(), and also less fragile
824+
has_git <- tryCatch({
825+
suppressWarnings(system2(
826+
"git", "--version",
827+
stdout = TRUE, stderr = null_file()
828+
))
829+
TRUE
830+
}, error = function(e) FALSE)
831+
832+
if (!has_git) throw(new_error("gitcreds_nogit_error"))
833+
}
834+
835+
null_file <- function() {
836+
if (get_os() == "windows") "nul:" else "/dev/null"
837+
}

R/list-creds.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ gitcreds_list <- function(url = "https://github.com",
122122

123123
credential_helper <- credential_helper %||% gitcreds_list_helpers()
124124
if (length(credential_helper) == 0) {
125-
gitcreds$throw(gitcreds$new_error("gitcreds_no_helper"))
125+
throw(new_error("gitcreds_no_helper"))
126126
}
127127
if (length(credential_helper) > 1) {
128-
gitcreds$throw(gitcreds$new_warning("gitcreds_multiple_helpers"))
128+
throw(gitcreds$new_warning("gitcreds_multiple_helpers"))
129129
credential_helper <- credential_helper[[1]]
130130
}
131131

132132
host <- NULL
133133
if (!is.null(url)) {
134-
purl <- gitcreds$parse_url(url)
134+
purl <- parse_url(url)
135135
if (!is.na(purl$host)) host <- purl$host
136136
if (!is.na(purl$protocol)) protocol <- purl$protocol
137137
}
@@ -142,7 +142,7 @@ gitcreds_list <- function(url = "https://github.com",
142142
"osxkeychain" = gitcreds_list_osxkeychain(url, host, protocol),
143143
"manager" = gitcreds_list_manager(url, host, protocol),
144144
"manager-core" = gitcreds_list_manager_core(url, host, protocol),
145-
gitcreds$throw(gitcreds$new_error(
145+
throw(new_error(
146146
"gitcreds_unknown_helper",
147147
credential_helper = credential_helper,
148148
message = sprintf(
@@ -222,7 +222,7 @@ is_manager_core_macos_item <- function(it, protocol, host) {
222222
if (!grepl("^git:", it$attributes$service)) return(FALSE)
223223
if (is.null(host)) return(TRUE)
224224
iturl <- sub("^git:", "", it$attributes$service)
225-
piturl <- gitcreds$parse_url(iturl)
225+
piturl <- parse_url(iturl)
226226
!is.na(piturl$host) && piturl$host == host &&
227227
!is.na(piturl$protocol) && piturl$protocol == protocol
228228
}
@@ -247,7 +247,7 @@ is_manager_core_win_item <- function(it, protocol, host) {
247247
if (!grepl("^git:", it$target_name)) return(FALSE)
248248
iturl <- sub("^git:", "", it$target_name)
249249
if (is.null(host)) return(TRUE)
250-
piturl <- gitcreds$parse_url(iturl)
250+
piturl <- parse_url(iturl)
251251
!is.na(piturl$host) && piturl$host == host &&
252252
!is.na(piturl$protocol) && piturl$protocol == protocol
253253
}

tests/testthat/helper.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ is_ci <- function() {
66
gc_test_that <- function(desc, code, os = NULL, helpers = NULL) {
77
if (!is_ci()) return()
88
if (!is.null(os)) {
9-
if (! gitcreds$get_os() %in% os) return()
9+
if (! get_os() %in% os) return()
1010
}
1111

1212
if (is.null(helpers)) {
13-
os <- gitcreds$get_os()
13+
os <- get_os()
1414
if (os == "windows") {
1515
helpers <- c("manager-core")
1616
} else if (os == "macos") {
@@ -43,11 +43,11 @@ gc_test_that_run <- function(desc, code) {
4343
options(gitcreds_test_consent = TRUE)
4444
}
4545

46-
if (gitcreds$get_os() == "windows") {
46+
if (get_os() == "windows") {
4747
cleanup_windows()
4848
on.exit(cleanup_windows(), add = TRUE)
4949
}
50-
if (gitcreds$get_os() == "macos") {
50+
if (get_os() == "macos") {
5151
cleanup_macos()
5252
on.exit(cleanup_macos(), add = TRUE)
5353
}
@@ -139,8 +139,8 @@ clear_helpers <- function() {
139139
local_helpers <- function(helpers, .local_envir = parent.frame()) {
140140
withr::defer(clear_helpers(), envir = .local_envir)
141141
clear_helpers()
142-
gitcreds$git_run(c("config", "--global", "--add", "credential.helper", "\"\""))
142+
git_run(c("config", "--global", "--add", "credential.helper", "\"\""))
143143
for (helper in helpers) {
144-
gitcreds$git_run(c("config", "--global", "--add", "credential.helper", helper))
144+
git_run(c("config", "--global", "--add", "credential.helper", helper))
145145
}
146146
}

tests/testthat/test-gitcreds-list.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ gc_test_that("gitcreds_list_manager_core_macos", os = "macos",
111111
"needs the `oskeyring` package"
112112
)
113113

114-
# FIXME: Testing interactively I get
115-
# Error in gitcreds$throw(gitcreds$new_error("gitcreds_unknown_helper", :
116-
# Unknown credential helper: `foo`, cannot list credentials
117-
# In addition: Warning message:
118-
# In gitcreds$throw(gitcreds$new_warning("gitcreds_multiple_helpers")) :
119-
# Multiple credential helpers, only using the first no credentials just yet
120114
expect_equal(gitcreds_list(), list())
121115

122116
cred <- list(

tests/testthat/test-username.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
gc_test_that("gitcreds_username_for_url", {
33
tmp <- withr::local_tempdir()
44
withr::local_dir(tmp)
5-
gitcreds$git_run(c("init", "."))
6-
gitcreds$git_run(c("config", "credential.username", "global"))
7-
gitcreds$git_run(c("config", "credential.https://example.com.username", "spec"))
5+
git_run(c("init", "."))
6+
git_run(c("config", "credential.username", "global"))
7+
git_run(c("config", "credential.https://example.com.username", "spec"))
88
expect_equal(gitcreds_username_for_url("https://example.com"), "spec")
99
expect_equal(gitcreds_username_for_url("https://foo.com"), "global")
10-
expect_equal(gitcreds$gitcreds_username(), "global")
11-
expect_equal(gitcreds$gitcreds_username("https://foo.com"), "global")
12-
expect_equal(gitcreds$gitcreds_username("https://example.com"), "spec")
10+
expect_equal(gitcreds_username(), "global")
11+
expect_equal(gitcreds_username("https://foo.com"), "global")
12+
expect_equal(gitcreds_username("https://example.com"), "spec")
1313
})
1414

15-
gc_test_that("gitcreds$gitcreds_username_generic", {
15+
gc_test_that("gitcreds_username_generic", {
1616
tmp <- withr::local_tempdir()
1717
withr::local_dir(tmp)
18-
gitcreds$git_run(c("init", "."))
19-
gitcreds$git_run(c("config", "credential.username", "global"))
20-
gitcreds$git_run(c("config", "credential.https://example.com.username", "spec"))
21-
expect_equal(gitcreds$gitcreds_username_generic(), "global")
18+
git_run(c("init", "."))
19+
git_run(c("config", "credential.username", "global"))
20+
git_run(c("config", "credential.https://example.com.username", "spec"))
21+
expect_equal(gitcreds_username_generic(), "global")
2222
})
2323

2424
gc_test_that("errors", {

tests/testthat/test-utils.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ test_that("ack", {
6262
})
6363

6464
gc_test_that("check_for_git", {
65-
expect_silent(gitcreds$check_for_git())
65+
expect_silent(check_for_git())
6666

6767
local_mocked_bindings(system2 = function(command, ...) {
6868
system2(basename(tempfile()), ...)
6969
})
7070
expect_error(
71-
gitcreds$check_for_git(),
71+
check_for_git(),
7272
class = "gitcreds_nogit_error"
7373
)
7474
})
@@ -104,8 +104,8 @@ test_that("throw", {
104104
})
105105

106106
test_that("null_file", {
107-
expect_silent(writeLines(letters, gitcreds$null_file()))
108-
expect_equal(readLines(gitcreds$null_file()), character())
107+
expect_silent(writeLines(letters, null_file()))
108+
expect_equal(readLines(null_file()), character())
109109
})
110110

111111
test_that("msg", {
@@ -206,7 +206,7 @@ test_that("is_interactive", {
206206
})
207207

208208
gc_test_that("git_run", {
209-
err <- tryCatch(gitcreds$git_run("qwertyzxcvbn"), error = function(x) x)
209+
err <- tryCatch(git_run("qwertyzxcvbn"), error = function(x) x)
210210
expect_s3_class(err, "git_error")
211211
expect_s3_class(err, "gitcreds_error")
212212
expect_match(conditionMessage(err), "System git failed:.*qwertyzxcvbn")

0 commit comments

Comments
 (0)