Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(diffFiles)
export(diffPreviousRevisions)
export(diffQced)
export(dirSummary)
export(fileRename)
export(getQcedRevision)
export(logAccept)
export(logAssign)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New features and changes

- `fileRename` added to the package to assist with renaming files in SVN and QClog. (#104)

- `diffFiles` can now display the entire file that is being diffed. (#115)

- Added `repoHistory` function to return history of all commits in the repository. (#116)
Expand Down
36 changes: 36 additions & 0 deletions R/fileRename.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Rename file in SVN and QClog
#'
#' @description
#' This function facilitates renaming a file in SVN. When run
#' the file will be renamed and a targeted commit to SVN will
#' be made to check in the new name. Additionally, if the file
#' exists in the QC log, all entries will be renamed and the updated
#' QC log will also be checked in to SVN.
#'
#' @param .filepath current file path of file to be renamed
#' @param .new_filepath new file path for file
#'
#' @export
fileRename <- function(.filepath, .new_filepath) {

# Check current file path exists
if(!file.exists(.filepath)) {
stop(paste0(.filepath, " does not exist"))
}

# Check if new file path already exists
if(file.exists(.new_filepath)) {
stop(paste0(.new_filepath, " already exists, can't overwrite"))
}

system(
glue::glue("svn mv {.filepath} {.new_filepath}")
)

qclog <- logRead()
qclog[qclog$file == .filepath,][["file"]] <- .new_filepath
qclog[qclog$origin == .filepath,][["origin"]] <- .new_filepath

logWrite(qclog, file = "QClog.csv")

}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ reference:
- svnLog
- svnExport
- demoRepo
- fileRename
- repoHistory
20 changes: 20 additions & 0 deletions man/fileRename.Rd

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

30 changes: 30 additions & 0 deletions tests/testthat/test-fileRename.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with_demoRepo({

fileRename("script/data-assembly.R", .new_filepath = "script/data-assembly2.R")
fileRename("script/combine-da.R", .new_filepath = "script/pk/combine-da.R")

testthat::test_that("fileRename renames file locally and in SVN history", {
expect_true(file.exists("script/data-assembly2.R"))
expect_true(!file.exists("script/data-assembly.R"))

expect_true(nrow(svnLog("script/data-assembly2.R")) > 1)
})

testthat::test_that("fileRename updates the file name in the QClog", {
qclog <- logRead()

expect_true(nrow(qclog[qclog$file == "script/data-assembly2.R",]) > 0)
expect_true(nrow(qclog[qclog$file == "script/data-assembly.R",]) == 0)
})

testthat::test_that("fileRename can move files to different directories", {

expect_true(!all(list.files("script") == "combine-da.R"))

expect_true(file.exists("script/pk/combine-da.R"))
expect_true(!file.exists("script/combine-da.R"))
})

})


Loading