Skip to content

Commit

Permalink
Don't locate unless root is NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Oct 17, 2024
1 parent 5fe0f2b commit 02de4dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
14 changes: 9 additions & 5 deletions R/root.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ root_open <- function(path, locate = TRUE, require_orderly = FALSE,
}
## This is going to error, but the error later will do.
path <- path$path
locate <- FALSE
}
if (is.null(path)) {
path <- getwd()
locate <- locate && TRUE
} else {
locate <- FALSE
}
assert_scalar_character(path)
assert_is_directory(path)
assert_scalar_character(path, call = call)
assert_is_directory(path, call = call)
if (locate) {
path_outpack <- find_file_descend(".outpack", path)
path_orderly <- find_file_descend("orderly_config.yml", path)
Expand All @@ -175,7 +177,8 @@ root_open <- function(path, locate = TRUE, require_orderly = FALSE,
i = "{names(order)[[2]]} was found at '{order[[2]]}'",
x = paste("{names(order)[[2]]} is nested within {names(order)[[1]]}",
"at {fs::path_rel(order[[2]], order[[1]])}"),
i = "How did you even do this? Please let us know!"))
i = "How did you even do this? Please let us know!"),
call = call)
}
path_open <- path_outpack
} else {
Expand Down Expand Up @@ -212,7 +215,8 @@ root_open <- function(path, locate = TRUE, require_orderly = FALSE,
"outpack root, but does not contain 'orderly_config.yml' so",
"cannot be used as an orderly root"),
i = 'Please run orderly2::orderly_init("{path}") to initialise',
i = "See ?orderly_init for more arguments to this function"))
i = "See ?orderly_init for more arguments to this function"),
call = call)
}

root_check_git(root, call)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ test_that("inform about weirdly nested roots: orderly in outpack", {
fs::dir_create(p)
file.create(file.path(p, "orderly_config.yml"))
err <- expect_error(
withr::with_dir(p, root_open(".", TRUE, TRUE)),
withr::with_dir(p, root_open(NULL, require_orderly = TRUE)),
"Found incorrectly nested orderly and outpack directories")

path_msg <- normalise_path(root$path)
Expand All @@ -171,7 +171,7 @@ test_that("inform about weirdly nested roots: orderly in outpack", {
p <- file.path(tmp, "a", "b")
root2 <- outpack_init_no_orderly(p)
err <- expect_error(
withr::with_dir(p, root_open(".", TRUE, TRUE)),
withr::with_dir(p, root_open(NULL, require_orderly = TRUE)),
"Found incorrectly nested orderly and outpack directories")
expect_equal(
err$body,
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-outpack-hash.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ test_that("can use user-facing hash functions", {

expect_equal(orderly_hash_data(str, "md5"), hash_data(str, "md5"))
expect_equal(orderly_hash_data(str, root = root), hash_data(str, "sha256"))
expect_equal(orderly_hash_data(str, root = path), hash_data(str, "sha256"))
expect_equal(withr::with_dir(path, orderly_hash_data(str)),
hash_data(str, "sha256"))

expect_equal(orderly_hash_file(tmp, "md5"), hash_file(tmp, "md5"))
expect_equal(orderly_hash_file(tmp, root = root), hash_file(tmp, "sha256"))
expect_equal(orderly_hash_file(tmp, root = path), hash_file(tmp, "sha256"))
expect_equal(withr::with_dir(path, orderly_hash_file(tmp)),
hash_file(tmp, "sha256"))
})
5 changes: 1 addition & 4 deletions tests/testthat/test-outpack-root.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ test_that("Can locate an outpack root", {
path <- root$path
p <- file.path(path, "a", "b", "c")
fs::dir_create(p)
expect_equal(
root_open(p, locate = TRUE, require_orderly = FALSE)$path,
root_open(path, locate = FALSE, require_orderly = FALSE)$path)
expect_equal(
withr::with_dir(
p,
root_open(".", locate = TRUE, require_orderly = FALSE)$path),
root_open(NULL, locate = TRUE, require_orderly = FALSE)$path),
root_open(path, locate = FALSE, require_orderly = FALSE)$path)
expect_identical(
root_open(root, locate = FALSE, require_orderly = FALSE), root)
Expand Down

0 comments on commit 02de4dc

Please sign in to comment.