Title: | Pre-Commit Hooks |
---|---|
Description: | Useful git hooks for R building on top of the multi-language framework 'pre-commit' for hook management. This package provides git hooks for common tasks like formatting files with 'styler' or spell checking as well as wrapper functions to access the 'pre-commit' executable. |
Authors: | Lorenz Walthert |
Maintainer: | Lorenz Walthert <[email protected]> |
License: | GPL-3 |
Version: | 0.4.3.9004 |
Built: | 2024-11-01 21:23:52 UTC |
Source: | https://github.com/lorenzwalthert/precommit |
Runs pre-commit autoupdate
.
autoupdate(root = here::here())
autoupdate(root = here::here())
root |
The path to the root directory of your project. |
The exit status from pre-commit autoupdate
(invisibly).
## Not run: autoupdate() ## End(Not run)
## Not run: autoupdate() ## End(Not run)
This installs pre-commit in the conda environment r-precommit. It
will be available to use across different git repositories. To update,
refer to update_precommit()
.
install_precommit(force = FALSE)
install_precommit(force = FALSE)
force |
Whether or not to force a re-installation. |
The path to the pre-commit executable (invisibly).
Other executable managers:
uninstall_precommit()
,
update_precommit()
,
version_precommit()
## Not run: install_precommit() ## End(Not run)
## Not run: install_precommit() ## End(Not run)
Open pre-commit related files
open_config(root = here::here()) open_wordlist(root = here::here())
open_config(root = here::here()) open_wordlist(root = here::here())
root |
The path to the root directory of your project. |
open_config()
: opens the pre-commit config file.
open_wordlist()
: opens the the WORDLIST file for the check-spelling hook
in inst/WORDLIST.
NULL
(invisibly). The function is called for its side effects.
Other helpers:
use_precommit()
## Not run: open_config() ## End(Not run) ## Not run: open_wordlist() ## End(Not run)
## Not run: open_config() ## End(Not run) ## Not run: open_wordlist() ## End(Not run)
path_precommit_exec()
simply reads the R option precommit.executable
,
path_pre_commit_exec()
is the old spelling and deprecated.
path_precommit_exec(check_if_exists = TRUE) path_pre_commit_exec(check_if_exists = TRUE)
path_precommit_exec(check_if_exists = TRUE) path_pre_commit_exec(check_if_exists = TRUE)
check_if_exists |
Whether or not to make sure the returned path also exists. |
A character vector of length one with the path to the pre-commit executable.
path_derive_precommit_exec()
for the heuristic to derive it from scratch.
## Not run: path_precommit_exec() ## End(Not run) ## Not run: path_pre_commit_exec() ## End(Not run)
## Not run: path_precommit_exec() ## End(Not run) ## Not run: path_pre_commit_exec() ## End(Not run)
Utility function to generate code snippets:
snippet_generate( snippet = "", open = rstudioapi::isAvailable(), root = here::here() )
snippet_generate( snippet = "", open = rstudioapi::isAvailable(), root = here::here() )
snippet |
Name of the snippet. |
open |
Whether or not to open the .pre-commit-config.yaml. The default
is |
root |
The path to the root directory of your project. |
Currently supported:
additional-deps-roxygenize: Code to paste into
.pre-commit-config.yaml
for the additional dependencies required by
the roxygenize hook.
Remove pre-commit from a repo or from your system.
uninstall_precommit(scope = "repo", ask = "user", root = here::here())
uninstall_precommit(scope = "repo", ask = "user", root = here::here())
scope |
Either "repo" or "user". "repo" removes pre-commit from your project, but you will be able to use it in other projects. With "user", you remove the pre-commit executable in the virtual python environment r-precommit so it won't be available in any project. When you want to do the latter, you should first do the former. |
ask |
Either "user", "repo" or "none" to determine in which case a prompt should show up to let the user confirm his action. |
root |
The path to the root directory of your project. |
NULL
(invisibly). The function is called for its side effects.
Other executable managers:
install_precommit()
,
update_precommit()
,
version_precommit()
## Not run: uninstall_precommit() ## End(Not run)
## Not run: uninstall_precommit() ## End(Not run)
Updates the conda installation of the upstream framework pre-commit. This
does not update the R package {precommit}
and only works if you choose
conda as your installation method. If you have problems updating, we suggest
deleting the conda environment r-precommit
(if you are sure nothing but
pre-commit depend on it) and do a fresh installation with
install_precommit()
.
update_precommit()
update_precommit()
The exit status of the conda update command (invisible).
Other executable managers:
install_precommit()
,
uninstall_precommit()
,
version_precommit()
Sets up continuous integration, or prompts the user to do it manually.
use_ci( ci = getOption("precommit.ci", "native"), force = FALSE, open = rstudioapi::isAvailable(), root = here::here() )
use_ci( ci = getOption("precommit.ci", "native"), force = FALSE, open = rstudioapi::isAvailable(), root = here::here() )
ci |
Specifies which continuous integration service to use. See
|
force |
Whether or not to overwrite an existing ci config file (only
relevant for |
open |
Whether or not to open pre-commit.ci
(if |
root |
The path to the root directory of your project. |
This function sets up pre-commit for your git repo.
use_precommit( config_source = getOption("precommit.config_source"), force = FALSE, legacy_hooks = "forbid", open = rstudioapi::isAvailable(), install_hooks = TRUE, ci = getOption("precommit.ci", "native"), autoupdate = install_hooks, root = here::here() )
use_precommit( config_source = getOption("precommit.config_source"), force = FALSE, legacy_hooks = "forbid", open = rstudioapi::isAvailable(), install_hooks = TRUE, ci = getOption("precommit.ci", "native"), autoupdate = install_hooks, root = here::here() )
config_source |
Path or URL to a |
force |
Whether or not to overwrite an existing ci config file (only
relevant for |
legacy_hooks |
How to treat hooks already in the repo which are not
managed by pre-commit. "forbid", the default, will cause |
open |
Whether or not to open |
install_hooks |
Whether to install environments for all available hooks.
If |
ci |
Specifies which continuous integration service to use. See
|
autoupdate |
Whether or not to run |
root |
The path to the root directory of your project. |
NULL
(invisibly). The function is called for its side effects.
You want to add pre-commit support to a git repo which does not have a
.pre-commit-config.yaml
. This involves adding
a pre-commit config file and making sure git will call the hooks before
the next commit.
You cloned a repo that has a .pre-commit-config.yaml
already. You need
to make sure git calls the hooks before the next commit.
Sets up a template .pre-commit-config.yaml
.
Autoupdates the template to make sure you get the latest versions of the hooks.
Installs the pre-commit script along with the hook environments with
$ pre-commit install --install-hooks
.
Opens the config file if RStudio is running.
You can use an existing .pre-commit-config.yaml
file when initializing
pre-commit with use_precommit()
using the argument config_source
to
copy an existing config file into your repo. This argument defaults to the R
option precommit.config_source
, so you may want to set this option in
your .Rprofile
for convenience. Note that this is not equivalent to the
--config
option in the CLI command pre-commit install
and similar,
which do not copy a config file into a project root (and allow to put it
under version control), but rather link it in some more or less transparent
way.
Other helpers:
open_config()
## Not run: use_precommit() ## End(Not run)
## Not run: use_precommit() ## End(Not run)
Initiate a pre-commit config file
use_precommit_config( config_source = getOption("precommit.config_source"), force = FALSE, open = rstudioapi::isAvailable(), verbose = FALSE, root = here::here() )
use_precommit_config( config_source = getOption("precommit.config_source"), force = FALSE, open = rstudioapi::isAvailable(), verbose = FALSE, root = here::here() )
config_source |
Path or URL to a |
force |
Whether to replace an existing config file. |
open |
Whether or not to open the .pre-commit-config.yaml after
it's been placed in your repo. The default is |
verbose |
Whether or not to communicate what's happening. |
root |
The path to the root directory of your project. |
Character vector of length one with the path to the config file used.
You can use an existing .pre-commit-config.yaml
file when initializing
pre-commit with use_precommit()
using the argument config_source
to
copy an existing config file into your repo. This argument defaults to the R
option precommit.config_source
, so you may want to set this option in
your .Rprofile
for convenience. Note that this is not equivalent to the
--config
option in the CLI command pre-commit install
and similar,
which do not copy a config file into a project root (and allow to put it
under version control), but rather link it in some more or less transparent
way.
## Not run: use_precommit_config() ## End(Not run)
## Not run: use_precommit_config() ## End(Not run)
Retrieves the version of the pre-commit executable used.
version_precommit()
version_precommit()
Other executable managers:
install_precommit()
,
uninstall_precommit()
,
update_precommit()