Skip to content

Commit

Permalink
Only remove .R extensions from old/new.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthegeek committed Aug 15, 2024
1 parent 13b4dc0 commit 8234e87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/rename-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' This is a potentially dangerous operation, so you must be using Git in
#' order to use this function.
#'
#' @param old,new Old and new file names (with or without extensions).
#' @param old,new Old and new file names (with or without `.R` extensions).
#' @export
rename_files <- function(old, new) {
check_uses_git()
Expand All @@ -23,8 +23,8 @@ rename_files <- function(old, new) {
untracked = TRUE
)

old <- path_ext_remove(old)
new <- path_ext_remove(new)
old <- sub("\\.R$", "", old)
new <- sub("\\.R$", "", new)

# R/ ------------------------------------------------------------------------
r_old_path <- proj_path("R", old, ext = "R")
Expand Down
2 changes: 1 addition & 1 deletion man/rename_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-rename-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ test_that("rename paths in test file", {
lines <- read_utf8(proj_path("tests", "testthat", "test-bar.R"))
expect_equal(lines, "test-bar.txt")
})

test_that("does not remove non-R dots in filename", {
create_local_package()
local_mocked_bindings(challenge_uncommitted_changes = \(...) invisible())
git_init()

file_create(proj_path("R/foo.bar.R"))
rename_files("foo.bar", "baz.qux")
expect_proj_file("R/baz.qux.R")
})

0 comments on commit 8234e87

Please sign in to comment.