Skip to content

Commit b89a478

Browse files
Merge pull request #438 from TNonet/tnonet/issue-429
Support --root for more hooks
2 parents 71c8c75 + 6cfb618 commit b89a478

File tree

12 files changed

+202
-8
lines changed

12 files changed

+202
-8
lines changed

API

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Exported functions
44

55
autoupdate(root = here::here())
6-
diff_requires_run_roxygenize(root = here::here())
6+
diff_requires_run_roxygenize(root = ".")
77
dirs_R.cache(hook_id)
88
install_precommit(force = FALSE)
99
may_require_permanent_cache(temp_cache_is_enough = FALSE)

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
4848
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
4949
warning("Please install r-lib/pkgapi to make sure the file API is kept
5050
up to date"); NULL} ) )
51-
RoxygenNote: 7.2.0
51+
RoxygenNote: 7.2.1
5252
SystemRequirements: git

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ editor_options:
44
wrap: 72
55
---
66

7+
# precommit v0.3.2.9001 (Development version)
8+
- `codemeta-description-updated`, `roxygenize`, and
9+
`use-tidy-description` now all support a `root` argument that
10+
specifies the directory in the git repo that contains the R package.
11+
Defaults to `.` since for most R package git repos, the git and R package
12+
root coincide.
13+
714
# precommit v0.3.2.9000
815

916
- `use_ci()` is now documented to take `NA`, not `NULL` for argument
1017
`ci` (#431).
18+
- `deps-in-desc`supports a `root` argument that specifies the directory in
19+
the git repo that contains the R package. Defaults to `.` since for most R
20+
package git repos, the git and R package root coincide.
1121

1222
# precommit v0.3.2
1323

R/roxygen2.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extract_diff_files <- function(files) {
2424
#' hook such as [roxygen2::roxygenize()] must run at all or not.
2525
#' @param root The root of project.
2626
#' @keywords internal
27-
extract_diff_root <- function(root = here::here()) {
27+
extract_diff_root <- function(root = ".") {
2828
assert_is_git_repo(root)
2929
repo <- git2r::repository(root)
3030
if (length(git2r::reflog(repo)) == 0) {
@@ -57,7 +57,7 @@ extract_diff_root <- function(root = here::here()) {
5757
#' diff_requires_run_roxygenize()
5858
#' }
5959
#' @export
60-
diff_requires_run_roxygenize <- function(root = here::here()) {
60+
diff_requires_run_roxygenize <- function(root = ".") {
6161
if (rlang::with_handlers(withr::with_namespace("git2r", FALSE), error = function(...) TRUE)) {
6262
generic <- paste0(
6363
" Please add the package as a dependency to ",

inst/hooks/exported/codemeta-description-updated.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env Rscript
22

3+
"A hook to make sure DESCRIPTION hasn’t been edited more recently than
4+
codemeta.json.
5+
6+
Usage:
7+
codemeta-description-updated [--root=<root_>] <files>...
8+
9+
Options:
10+
--root=<root_> Path relative to the git root that contains the R package
11+
root [default: .].
12+
13+
" -> doc
14+
15+
16+
arguments <- docopt::docopt(doc)
17+
setwd(arguments$root)
18+
319
# adapted from https://github.com/lorenzwalthert/precommit/blob/f4413cfe6282c84f7176160d06e1560860c8bd3d/inst/hooks/exported/readme-rmd-rendered
420
if (!file.exists("DESCRIPTION")) {
521
rlang::abort("No `DESCRIPTION` found in repository.")

inst/hooks/exported/roxygenize.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ This check should run *after* check that modify the files that are passed to
1414
them (like styler) because they will never modify their input .R files.
1515
1616
Usage:
17-
roxygenize [--no-warn-cache] <files>...
17+
roxygenize [--no-warn-cache] [--root=<root_>] <files>...
1818
1919
Options:
2020
--no-warn-cache Suppress the warning about a missing permanent cache.
21+
--root=<root_> Path relative to the git root that contains the R package root [default: .].
2122
2223
" -> doc
2324
arguments <- docopt::docopt(doc)
25+
arguments$files <- normalizePath(arguments$files) # because working directory changes to root
26+
setwd(arguments$root)
27+
2428
if (packageVersion("precommit") < "0.1.3.9010") {
2529
rlang::abort(paste(
2630
"This hooks only works with the R package {precommit} >= 0.1.3.9010",

inst/hooks/exported/use-tidy-description.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
#!/usr/bin/env Rscript
2+
3+
"A hook to run usethis::use_tidy_description() to ensure dependencies are
4+
ordered alphabetically and fields are in standard order.
5+
6+
Usage:
7+
use-tidy-description [--root=<root_>] <files>...
8+
9+
Options:
10+
--root=<root_> Path relative to the git root that contains the R package root [default: .].
11+
12+
" -> doc
13+
14+
15+
arguments <- docopt::docopt(doc)
16+
setwd(arguments$root)
17+
18+
if (!file.exists("DESCRIPTION")) {
19+
rlang::abort("No `DESCRIPTION` found in repository.")
20+
}
21+
222
description <- desc::description$new()
323
description_old <- description$clone(deep = TRUE)
424
deps <- description$get_deps()

man/diff_requires_run_roxygenize.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/extract_diff_root.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git_init.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)