@@ -35,6 +35,10 @@ install_system <- function(force) {
3535# ' @param force Whether or not to force a re-installation.
3636# ' @return
3737# ' The path to the pre-commit executable (invisibly).
38+ # ' @examples
39+ # ' \dontrun{
40+ # ' install_precommit()
41+ # ' }
3842# ' @export
3943install_precommit <- function (force = FALSE ) {
4044 install_system(force = force )
@@ -50,22 +54,21 @@ install_impl <- function() {
5054}
5155
5256install_repo <- function (root , install_hooks , legacy_hooks ) {
53-
5457 withr :: with_dir(root , {
5558 remove_usethis_readme_hook()
5659 out <- call_precommit(
57- " install" ,
58- if (install_hooks ) " --install-hooks" ,
59- if (legacy_hooks == ' remove' ) " --overwrite"
60+ " install" ,
61+ if (install_hooks ) " --install-hooks" ,
62+ if (legacy_hooks == " remove" ) " --overwrite"
6063 )
6164 if (out $ exit_status == 0 ) {
6265 if (any(grepl(" Use -f to use only pre-commit." , out $ stdout , fixed = TRUE ))) {
63- if (legacy_hooks == ' forbid' ) {
66+ if (legacy_hooks == " forbid" ) {
6467 rlang :: abort(paste(
6568 " There are existing hooks installed for this repo and the argument" ,
66- " `legacy_hooks` is set to `'forbid'`. We recommend inspecting these" ,
69+ " `legacy_hooks` is set to `'forbid'`. We recommend inspecting these" ,
6770 " and removing them manually or - if you are sure you don't need" ,
68- " them anymore - call this function again with" ,
71+ " them anymore - call this function again with" ,
6972 " `legacy_hooks = 'remove'` to remove them for you." ,
7073 " If you want to continue to use these hooks, set" ,
7174 " `legacy_hooks` to `'allow'`, which means pre-commit will run in " ,
@@ -91,18 +94,18 @@ install_repo <- function(root, install_hooks, legacy_hooks) {
9194
9295remove_usethis_readme_hook <- function () {
9396 legacy <- readLines(
94- system.file(" usethis-legacy-hook" , package = ' precommit' ),
97+ system.file(" usethis-legacy-hook" , package = " precommit" ),
9598 encoding = " UTF-8"
9699 )
97100 candidate <- " .git/hooks/pre-commit"
98101 if (fs :: file_exists(candidate )) {
99102 if (identical(readLines(candidate , encoding = " UTF-8" ), legacy )) {
100103 fs :: file_delete(candidate )
101104 usethis :: ui_info(paste(
102- " Removed the render-README hook, which was added with" ,
105+ " Removed the render-README hook, which was added with" ,
103106 " `usethis::use_readme_rmd()` to this repo at some point in the past." ,
104- " {{precommit}}'s equivalent is the hook with the id 'readme-rmd-rendered'." ,
105- " Add the hook to your .pre-commit-config.yaml as described here:" ,
107+ " {{precommit}}'s equivalent is the hook with the id 'readme-rmd-rendered'." ,
108+ " Add the hook to your .pre-commit-config.yaml as described here:" ,
106109 " https://lorenzwalthert.github.io/precommit/#usage."
107110 ))
108111 }
@@ -123,6 +126,10 @@ remove_usethis_readme_hook <- function() {
123126# ' @inheritParams fallback_doc
124127# ' @return
125128# ' `NULL` (invisibly). The function is called for its side effects.
129+ # ' @examples
130+ # ' \dontrun{
131+ # ' uninstall_precommit()
132+ # ' }
126133# ' @export
127134uninstall_precommit <- function (scope = " repo" ,
128135 ask = " user" ,
0 commit comments