| Title: | Running 'git' Pre-Commit Hooks |
|---|---|
| Description: | Git hook scripts are useful for identifying simple issues before submission to code review. 'captain' (hook) is an R package to manage and run git pre-commit hooks. |
| Authors: | Alex Yahiaoui Martinez [aut, cre] (ORCID: <https://orcid.org/0000-0002-5315-675X>) |
| Maintainer: | Alex Yahiaoui Martinez <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.2.0 |
| Built: | 2026-05-23 08:30:15 UTC |
| Source: | https://github.com/alexym1/captain |
Handle .pre-commit-config file for running pre-commit hooks
create_precommit_config(filename = path_precommit_files()[1], force = FALSE) edit_precommit_config()create_precommit_config(filename = path_precommit_files()[1], force = FALSE) edit_precommit_config()
filename |
the name of the file to create |
force |
overwrite the file if it already exists |
create_precommit_config() will create a .pre-commit-config file in the current project.
Only one file is allowed in the project and should be in the root directory or in the inst directory such as:
inst/pre-commit/.pre-commit-config.yml
inst/pre-commit/.pre-commit-config.yaml
cli messages related to the creation and edition of the .pre-commit-config file.
Add pre-commit hooks to .pre-commit-config.y*ml file
create_precommit_hook( filename, id, name, description, language = "system", always_run = TRUE )create_precommit_hook( filename, id, name, description, language = "system", always_run = TRUE )
filename |
The name of script file |
id |
The unique identifier for the hook |
name |
A descriptive name for the hook |
description |
A brief description of what the hook does |
language |
The programming language or environment for the hook (default is "system") |
always_run |
Logical, whether the hook should always run (default is TRUE) |
cli messages related to the creation of the hook and updating the config file. Create inst/pre-commit/hooks/{filename}.R script and update .pre-commit-config.y*ml file.
Install pre-commit file in the repo.
install_precommit(force = FALSE, ...)install_precommit(force = FALSE, ...)
force |
overwrite the file if it already exists |
... |
additional arguments to pass to |
cli messages related to the installation of pre-commit files. Create inst/pre-commit folder and .git/hooks/pre-commit file.
Run pre-commit hooks
run_precommit(path = ".git/hooks/pre-commit")run_precommit(path = ".git/hooks/pre-commit")
path |
path of the pre-commit file |
cli message related to the run of all git precommit hooks.
Enable or disable individual hooks in the .pre-commit-config.y*ml file.
toggle_precommit_hook(...)toggle_precommit_hook(...)
... |
One or more named lists, each with fields:
|
Disabling a hook sets stages: [manual] on the hook entry, which tells pre-commit to skip it during
normal git commits. The hook can then only be triggered explicitly with pre-commit run --hook-stage manual.
Enabling a hook removes the stages field, restoring default behaviour.
cli messages describing the result. When disabled, the hook's stages field is set to [manual]
so it is skipped during normal git runs. When enabled, the stages restriction is removed.
## Not run: toggle_precommit_hook( list(id = "lintr", enable = FALSE), list(id = "styler", enable = TRUE) ) ## End(Not run)## Not run: toggle_precommit_hook( list(id = "lintr", enable = FALSE), list(id = "styler", enable = TRUE) ) ## End(Not run)