Skip to content

Commit 7a60b4c

Browse files
committed
feat: improve text_file_paths_default__
1 parent cb19306 commit 7a60b4c

File tree

7 files changed

+72
-132
lines changed

7 files changed

+72
-132
lines changed

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ export(example_text_file_names)
2121
export(example_text_file_path)
2222
export(example_text_file_paths)
2323
export(extract_keyed_comment_blocks)
24-
export(pkg_doc_fun)
25-
export(pkg_doc_package_description)
2624
export(render_codedoc)
2725
export(render_codedoc_)

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<!-- generated by R package codedoc; do not modify! -->
22

3+
## News for version 0.8.0
4+
5+
### codedoc::extract_keyed_comment_blocks
6+
7+
`codedoc::extract_keyed_comment_blocks` default for `text_file_paths`
8+
improved: It now excludes files ignored by `git` if it has been installed on
9+
the system.
10+
11+
312
## News for version 0.7.0
413

514
### codedoc::extract_keyed_comment_blocks

R/collect_raw.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ text_file_paths_default__ <- function() {
221221
# winslash = "/",
222222
# mustWork = FALSE
223223
# )
224+
# if (git_is_installed__() && git_used_here__()) {
225+
# tfp <- tfp[!git_ignores__(tfp)]
226+
# }
224227
# tfp <- tfp[!grepl("/renv/library/", tfp)]
225228
# }
226229
# ```
@@ -236,6 +239,11 @@ text_file_paths_default__ <- function() {
236239
# through files in installed R packages. That is the typical directory for
237240
# packages installed by package `renv`.
238241
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2025-04-10", "0.7.0")
242+
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2025-04-16", "0.8.0")
243+
# `codedoc::extract_keyed_comment_blocks` default for `text_file_paths`
244+
# improved: It now excludes files ignored by `git` if it has been installed on
245+
# the system.
246+
# @codedoc_comment_block news("codedoc::extract_keyed_comment_blocks", "2025-04-16", "0.8.0")
239247
out <- {
240248
tfp <- dir(
241249
path = getwd(),
@@ -250,6 +258,9 @@ text_file_paths_default__ <- function() {
250258
mustWork = FALSE
251259
)
252260
tfp <- tfp[!grepl("/renv/library/", tfp)]
261+
if (git_is_installed__() && git_used_here__()) {
262+
tfp <- tfp[!git_ignores__(tfp)]
263+
}
253264
tfp
254265
}
255266
return(out)

R/git.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
git_is_installed__ <- function() {
2+
tryCatch(
3+
expr = is.character(
4+
system2("git", "version", stdout = TRUE, stderr = TRUE)
5+
),
6+
error = function(e) FALSE,
7+
warning = function(w) FALSE
8+
)
9+
}
10+
11+
git_used_here__ <- function() {
12+
tryCatch(
13+
expr = is.character(
14+
system2("git", "status", stdout = TRUE, stderr = TRUE)
15+
),
16+
error = function(e) FALSE,
17+
warning = function(w) FALSE
18+
)
19+
}
20+
21+
git_ignores__ <- function(file_paths) {
22+
dbc::assert_prod_input_file_exists(file_paths)
23+
not_ignored_file_paths <- system2(
24+
"git",
25+
c("ls-files", "--cached", "--others", "--exclude-standard"),
26+
stdout = TRUE
27+
)
28+
not_ignored_file_paths <- normalizePath(
29+
not_ignored_file_paths,
30+
winslash = "/",
31+
mustWork = FALSE
32+
)
33+
file_paths <- normalizePath(
34+
file_paths,
35+
winslash = "/",
36+
mustWork = FALSE
37+
)
38+
!file_paths %in% not_ignored_file_paths
39+
}

man/codedoc-package.Rd

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

man/extract_keyed_comment_blocks.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.

man/pkg_doc.Rd

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

0 commit comments

Comments
 (0)