diff --git a/NAMESPACE b/NAMESPACE index 61c30e0..dc8099e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,9 @@ S3method(rm_data,character) S3method(rm_data,default) S3method(rm_data,git_repository) S3method(summary,git2rdata) +S3method(update_description,character) +S3method(update_description,default) +S3method(update_description,git_repository) S3method(upgrade_data,character) S3method(upgrade_data,default) S3method(upgrade_data,git_repository) diff --git a/R/update_description.R b/R/update_description.R index 3a5830b..ac65ca5 100644 --- a/R/update_description.R +++ b/R/update_description.R @@ -18,6 +18,30 @@ #' @importFrom assertthat assert_that has_name update_description <- function( file, root = ".", field_description, name, title, description +) { + UseMethod("update_description", root) +} + +#' @export +update_description.default <- function( + file, root = ".", field_description, name, title, description +) { + stop("a 'root' of class ", class(root), " is not supported", call. = FALSE) +} + +#' @export +update_description.git_repository <- function( + file, root = ".", field_description, name, title, description +) { + update_description( + file = file, root = workdir(root), name = name, title = title, + description = description, field_description = field_description + ) +} + +#' @export +update_description.character <- function( + file, root = ".", field_description, name, title, description ) { root <- normalizePath(root, winslash = "/", mustWork = TRUE) file <- clean_data_path(root = root, file = file) diff --git a/tests/testthat/test_c_description.R b/tests/testthat/test_d_description.R similarity index 84% rename from tests/testthat/test_c_description.R rename to tests/testthat/test_d_description.R index df58d68..360440f 100644 --- a/tests/testthat/test_c_description.R +++ b/tests/testthat/test_d_description.R @@ -1,4 +1,11 @@ test_that("description", { + expect_error( + update_description( + file = "test", root = data.frame() + ), + "a 'root' of class data.frame is not supported" + ) + root <- tempfile(pattern = "git2rdata-description") dir.create(root) @@ -35,6 +42,12 @@ test_that("description", { expect_output(display_metadata(output, minimal = FALSE), "Table name: NA") expect_output(display_metadata(output), "Table name: NA") + root <- git2r::init(root) + git2r::config(root, user.name = "Alice", user.email = "alice@example.org") + writeLines("ignore.*\nforce.*", file.path(git2r::workdir(root), ".gitignore")) + git2r::add(root, ".gitignore") + commit(root, "initial commit") + expect_null( update_description( file = "test", root = root, name = "my_table", title = "My Table",