Skip to content

Commit f8d9cf6

Browse files
fix: allow both unstaged, e.g. for pre-commit run --all-files
1 parent e53d01b commit f8d9cf6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

inst/hooks/exported/readme-rmd-rendered.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ if (file.exists("README.md")) {
3535
source_staged <- source_file %in% file_names_staged
3636
output_staged <- "README.md" %in% file_names_staged
3737

38-
if (!source_staged || !output_staged) {
39-
rlang::abort(paste(source_file, "and README.md must both be staged."))
38+
if (sum(source_staged, output_staged) == 1) {
39+
rlang::abort(paste(
40+
source_file, "and README.md must both be either staged or unstaged."
41+
))
4042
}
4143
}

tests/testthat/test-hook-readme-rmd-rendered.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if (has_git()) {
4747
run_test("readme-rmd-rendered",
4848
file_name = c("README.Rmd", "README.md"),
4949
suffix = "",
50-
std_err = "must both be staged",
50+
std_err = "must both be either staged",
5151
std_out = NULL,
5252
file_transformer = function(files) {
5353
if (length(files) > 1) {
@@ -112,7 +112,7 @@ if (has_git()) {
112112
run_test("readme-rmd-rendered",
113113
file_name = c("README.qmd", "README.md"),
114114
suffix = "",
115-
std_err = "must both be staged",
115+
std_err = "must both be either staged",
116116
std_out = NULL,
117117
file_transformer = function(files) {
118118
if (length(files) > 1) {

0 commit comments

Comments
 (0)