From 02de4dca6fed4d323c4ea63f7747377b0e11cd63 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Thu, 17 Oct 2024 13:39:51 +0100 Subject: [PATCH] Don't locate unless root is NULL --- R/root.R | 14 +++++++++----- tests/testthat/test-init.R | 4 ++-- tests/testthat/test-outpack-hash.R | 2 -- tests/testthat/test-outpack-root.R | 5 +---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/R/root.R b/R/root.R index b94e251e..49bddc17 100644 --- a/R/root.R +++ b/R/root.R @@ -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) @@ -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 { @@ -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) diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R index dd854848..0cccad3b 100644 --- a/tests/testthat/test-init.R +++ b/tests/testthat/test-init.R @@ -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) @@ -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, diff --git a/tests/testthat/test-outpack-hash.R b/tests/testthat/test-outpack-hash.R index 3fe184d2..f3bdb9d3 100644 --- a/tests/testthat/test-outpack-hash.R +++ b/tests/testthat/test-outpack-hash.R @@ -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")) }) diff --git a/tests/testthat/test-outpack-root.R b/tests/testthat/test-outpack-root.R index 0352aea9..ee252d67 100644 --- a/tests/testthat/test-outpack-root.R +++ b/tests/testthat/test-outpack-root.R @@ -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)