Skip to content

Commit 992fb8e

Browse files
don't install hooks
#295 (comment)
1 parent b654bd8 commit 992fb8e

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

tests/testthat/test-conda.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,37 @@ if (!on_cran()) {
66
})
77

88
test_that("can use pre-commit", {
9-
tempdir <- local_test_setup(quiet = FALSE)
9+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
1010
expect_message(
1111
use_precommit(open = FALSE, force = TRUE, root = tempdir),
1212
"to get the latest"
1313
)
1414
expect_message(
15-
use_precommit(open = FALSE, force = FALSE, root = tempdir),
15+
use_precommit(open = FALSE, force = FALSE, install_hooks = FALSE, root = tempdir),
1616
"There is already "
1717
)
1818
})
1919

2020
test_that("fails early if repo is not a git repo ", {
21-
tempdir <- local_test_setup(git = FALSE, quiet = FALSE)
21+
tempdir <- local_test_setup(git = FALSE, quiet = FALSE, install_hooks = FALSE)
2222

2323
expect_error(
24-
use_precommit(open = FALSE, root = tempdir),
24+
use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir),
2525
"is not a git repo"
2626
)
2727
})
2828

2929
test_that("can use custom config file ", {
30-
tempdir1 <- local_test_setup()
31-
tempdir2 <- local_test_setup()
30+
tempdir1 <- local_test_setup(install_hooks = FALSE)
31+
tempdir2 <- local_test_setup(install_hooks = FALSE)
3232

3333
path_custom <- fs::path(tempdir2, "some-precommit.yaml")
3434
new_text <- "# 4js93"
3535
readLines(system.file("pre-commit-config-proj.yaml", package = "precommit")) %>%
3636
c(new_text) %>%
3737
writeLines(path_custom)
3838
git2r::init(tempdir1)
39-
use_precommit(config_source = path_custom, open = FALSE, force = TRUE, root = tempdir1)
39+
use_precommit(config_source = path_custom, open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir1)
4040
config <- readLines(fs::path(tempdir1, ".pre-commit-config.yaml"))
4141
expect_equal(
4242
config[length(config)],
@@ -45,33 +45,33 @@ if (!on_cran()) {
4545
})
4646

4747
test_that("existing hooks are recognized", {
48-
tempdir <- local_test_setup(quiet = FALSE)
48+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
4949
withr::with_dir(tempdir, {
5050
git2r::init()
5151
usethis::proj_set(".")
5252
usethis::use_readme_rmd(open = FALSE)
5353

5454
# usethis hook is removed without error
5555
expect_message(
56-
use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."),
56+
use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."),
5757
"Removed the render-README hook,"
5858
)
5959
writeLines(letters, ".git/hooks/pre-commit")
6060
expect_error(
61-
use_precommit(legacy_hooks = "forbid", open = FALSE, root = "."),
61+
use_precommit(legacy_hooks = "forbid", open = FALSE, install_hooks = FALSE, root = "."),
6262
"existing hooks installed"
6363
)
6464

6565
# tolerate other hook scripts in migration mode
6666
expect_message(
67-
use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, root = "."),
67+
use_precommit(legacy_hooks = "allow", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."),
6868
"Running in migration"
6969
)
7070

7171
# can also remove other hooks
7272
writeLines(letters, ".git/hooks/pre-commit")
7373
expect_message(
74-
use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, root = "."),
74+
use_precommit(legacy_hooks = "remove", force = TRUE, open = FALSE, install_hooks = FALSE, root = "."),
7575
"Sucessfully installed"
7676
)
7777
})
@@ -80,7 +80,7 @@ if (!on_cran()) {
8080

8181
test_that("Can uninstall pre-commit (repo scope)", {
8282
# with all files there
83-
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE)
83+
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE)
8484
expect_message(
8585
uninstall_precommit(scope = "repo", root = tempdir),
8686
"Uninstalled pre-commit from repo scope.*"
@@ -94,7 +94,7 @@ if (!on_cran()) {
9494
)
9595

9696
# when there is no pre-commit.yaml anymore
97-
suppressMessages(use_precommit(open = FALSE, force = TRUE, root = tempdir))
97+
suppressMessages(use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir))
9898
fs::file_delete(fs::path(tempdir, ".pre-commit-config.yaml"))
9999
expect_message(
100100
uninstall_precommit(scope = "repo", root = tempdir),
@@ -104,13 +104,13 @@ if (!on_cran()) {
104104

105105
test_that("Can uninstall (userly)", {
106106
if (not_conda()) {
107-
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE)
107+
tempdir <- local_test_setup(use_precommit = TRUE, quiet = FALSE, install_hooks = FALSE)
108108
expect_error(
109109
uninstall_precommit(scope = "user", ask = "none", root = tempdir),
110110
"installed with conda"
111111
)
112112
} else {
113-
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE)
113+
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE)
114114
expect_message(
115115
uninstall_precommit(scope = "user", ask = "none", root = tempdir),
116116
"Removed pre-commit from"
@@ -124,18 +124,18 @@ if (!on_cran()) {
124124

125125
test_that("use_precommit fails when no user installation is found", {
126126
skip_if(not_conda())
127-
expect_error(use_precommit(open = FALSE, root = tempdir), "installed on your system")
127+
expect_error(use_precommit(open = FALSE, install_hooks = FALSE, root = tempdir), "installed on your system")
128128
})
129129

130130
test_that("can install pre-commit with remote config", {
131131
if (!not_conda()) {
132132
expect_error(install_precommit(), NA)
133133
}
134-
tempdir <- local_test_setup(quiet = FALSE)
134+
tempdir <- local_test_setup(quiet = FALSE, install_hooks = FALSE)
135135
expect_message(
136136
use_precommit(
137137
example_remote_config(),
138-
open = FALSE, force = TRUE, root = tempdir
138+
open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir
139139
),
140140
"to get the latest"
141141
)
@@ -145,14 +145,14 @@ if (!on_cran()) {
145145
if (!not_conda()) {
146146
expect_message(install_precommit(), "already installed")
147147
}
148-
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE)
148+
tempdir <- local_test_setup(use_precommit = FALSE, quiet = FALSE, install_hooks = FALSE)
149149
withr::with_dir(
150150
tempdir,
151151
{
152152
withr::defer(call_and_capture("git", "config --unset-all core.hooksPath"))
153153
call_and_capture("git", "config core.hooksPath .githooks")
154154
expect_error(
155-
use_precommit(open = FALSE, force = TRUE, root = tempdir),
155+
use_precommit(open = FALSE, force = TRUE, install_hooks = FALSE, root = tempdir),
156156
"stdout: [ERROR] Cowardly refusing to install hooks with `core.hooksPath` set.",
157157
fixed = TRUE
158158
)

tests/testthat/test-config.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ test_that(".Rbuildignore is written to the right directory when root is relative
5252
})
5353
withr::with_dir(
5454
fs::path_dir(root),
55-
use_precommit_config(root = fs::path_file(root))
55+
use_precommit_config(install_hooks = FALSE, root = fs::path_file(root))
5656
)
5757
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
5858
})
@@ -66,6 +66,6 @@ test_that(".Rbuildignore is written to the right directory when root is absolute
6666
desc$set(Package = "test.pkg")
6767
desc$write("DESCRIPTION")
6868
})
69-
use_precommit_config(root = root)
69+
use_precommit_config(install_hooks = FALSE, root = root)
7070
expect_true(fs::file_exists(fs::path(root, ".Rbuildignore")))
7171
})

tests/testthat/test-setup.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("snippet generation works", {
2-
local_test_setup(git = FALSE, use_precommit = FALSE, package = TRUE)
2+
local_test_setup(git = FALSE, use_precommit = FALSE, package = TRUE, install_hooks = FALSE)
33
usethis::use_package("styler")
44
expect_warning(
55
out <- capture_output(snippet_generate("additional-deps-roxygenize")),

0 commit comments

Comments
 (0)