Skip to content

Commit

Permalink
Revert "always expand paths"
Browse files Browse the repository at this point in the history
This reverts commit 76fec81.
  • Loading branch information
lorenzwalthert committed Dec 10, 2021
1 parent 2148df6 commit 895f43a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use_precommit_config <- function(config_source = getOption("precommit.config_sou
)
escaped_name_target <- "^\\.pre-commit-config\\.yaml$"
name_target <- ".pre-commit-config.yaml"
if (!file_exists(fs::path(root, name_target)) | force) {
if (!fs::file_exists(fs::path(root, name_target)) | force) {
fs::file_copy(
config_source,
fs::path(root, name_target),
Expand Down Expand Up @@ -103,7 +103,7 @@ set_config_source <- function(config_source,
)
config_source <- system.file(name_origin, package = "precommit")
}
if (!file_exists(config_source)) {
if (!fs::file_exists(config_source)) {
rlang::abort(paste0(
"File ", config_source, " does not exist. Please use the ",
"argument `config_source` to provide a path to an existing ",
Expand Down
6 changes: 3 additions & 3 deletions R/exec.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path_precommit_exec <- function(check_if_exists = TRUE) {
if (!check_if_exists) {
return(final)
}
if (!file_exists(final)) {
if (!fs::file_exists(final)) {
rlang::abort(paste0(
"pre-commit executable does not exist at ",
final,
Expand Down Expand Up @@ -112,7 +112,7 @@ path_warn_multiple_execs <- function(paths) {

path_candidate_to_actual <- function(candidate) {
assumed <- fs::path(candidate, precommit_executable_file())
assumed[file_exists(assumed)]
assumed[fs::file_exists(assumed)]
}

path_derive_precommit_exec_linux <- function() {
Expand Down Expand Up @@ -200,7 +200,7 @@ path_derive_precommit_exec_conda_impl <- function(conda_env) {
ifelse(is_windows(), "Scripts", ""),
precommit_executable_file()
)
unname(ifelse(file_exists(derived), derived, ""))
unname(ifelse(fs::file_exists(derived), derived, ""))
},
error = function(e) ""
)
Expand Down
8 changes: 4 additions & 4 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ remove_usethis_readme_hook <- function() {
encoding = "UTF-8"
)
candidate <- ".git/hooks/pre-commit"
if (file_exists(candidate)) {
if (fs::file_exists(candidate)) {
if (identical(readLines(candidate, encoding = "UTF-8"), legacy)) {
fs::file_delete(candidate)
cli::cli_alert_info(paste(
Expand Down Expand Up @@ -172,7 +172,7 @@ uninstall_precommit <- function(scope = "repo",
if (scope == "repo") {
uninstall_repo(ask = (ask %in% c("repo", "both")))
path_config <- ".pre-commit-config.yaml"
if (file_exists(path_config)) {
if (fs::file_exists(path_config)) {
fs::file_delete(path_config)
cli::cli_alert_success("Removed .pre-commit-config.yaml")
}
Expand Down Expand Up @@ -260,7 +260,7 @@ uninstall_repo <- function(ask) {
}
}
path_file <- ".pre-commit-config.yaml"
if (file_exists(path_file)) {
if (fs::file_exists(path_file)) {
fs::file_delete(path_file)
cli::cli_alert_success(paste(
"Removed .pre-commit-config.yaml. If you want your collaborators",
Expand All @@ -280,5 +280,5 @@ uninstall_repo <- function(ask) {
}

is_installed <- function() {
file_exists(path_precommit_exec(check_if_exists = FALSE))
fs::file_exists(path_precommit_exec(check_if_exists = FALSE))
}
6 changes: 1 addition & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ is_url <- function(text) {
inherits("url")
}

file_exists <- function(...) {
fs::file_exists(fs::path_expand(...))
}


path_if_exist <- function(...) {
path <- c(...)
path[file_exists(path)]
path[fs::file_exists(path)]
}

is_conda_installation <- function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-conda.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if (!on_cran()) {
uninstall_precommit(scope = "repo", root = tempdir),
"Uninstalled pre-commit from repo scope.*"
)
expect_false(file_exists(fs::path(tempdir, ".pre-commit-config.yaml")))
expect_false(fs::file_exists(fs::path(tempdir, ".pre-commit-config.yaml")))
expect_false(any(grepl(".pre-commit", readline(fs::path(tempdir, ".Rbuildignore")))))
# second time
expect_message(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_that(".Rbuildignore is written to the right directory when root is relative
fs::path_dir(root),
use_precommit_config(root = fs::path_file(root))
)
expect_true(file_exists(fs::path(root, ".Rbuildignore")))
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
})

test_that(".Rbuildignore is written to the right directory when root is absolute", {
Expand All @@ -67,5 +67,5 @@ test_that(".Rbuildignore is written to the right directory when root is absolute
desc$write("DESCRIPTION")
})
use_precommit_config(root = root)
expect_true(file_exists(fs::path(root, ".Rbuildignore")))
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ test_that("GitHub Action CI setup works", {
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
use_ci("gha", root = getwd())
expect_true(file_exists(".github/workflows/pre-commit.yaml"))
expect_true(fs::file_exists(".github/workflows/pre-commit.yaml"))
})

test_that("Pre-commit CI setup works", {
local_test_setup(
git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE
)
use_ci(root = getwd())
expect_false(file_exists(".github/workflows/pre-commit.yaml"))
expect_false(fs::file_exists(".github/workflows/pre-commit.yaml"))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("tests don't write to styler-perm", {
skip_on_cran()
expect_false(file_exists(
expect_false(fs::file_exists(
fs::path(R.cache::getCacheRootPath(), "styler-perm")
))
})

0 comments on commit 895f43a

Please sign in to comment.