Writes a commit-msg git hook that runs gate() on each commit (rules
6.1 to 6.3). It says what it will write before it writes anything, and
running it again changes nothing. suppressMessages() silences it.
Arguments
- path
A directory in the project, which must hold
_weft.ymland be inside a git work tree.- remove
Remove the hook instead of installing it.
- overwrite
Replace a hook weft wrote that has since been edited.
- rscript
The
Rscriptthe hook runs. Default: the one of this R.- lib
The library paths the hook gives R, which must hold weft. Default:
.libPaths().
Value
The paths written, invisibly (character() when nothing changed).
Details
The script is POSIX sh, written to the repository's hooks folder (the one
git rev-parse --git-path hooks names, so a linked worktree uses the main
repository's). It records the Rscript and the library paths of the session
that ran use_hooks(), and runs R with --no-init-file --no-environ, so the
project's .Rprofile (renv, weft_setup()) and .Renviron (which could
replace the recorded library paths) are not read by the hook. When R or weft
cannot be found the commit fails with a message that names use_hooks() and
git commit --no-verify; the latter skips the hook for one commit.
No
commit-msghook, andcore.hooksPathunset: the hook is written.A hook weft wrote (it has a
weft-file: use_hooksline) and has not been edited: rewritten when its text would differ, else kept. Edited: left as it is, unlessoverwrite = TRUE.Another tool's hook, or
core.hooksPathset (a hook manager): left alone, also underoverwrite = TRUE. The script goes to<git common dir>/weft/commit-msg, and the call prints the line to add to the hook your setup runs (and arepo: localentry when there is a.pre-commit-config.yaml).
remove = TRUE deletes the hook when it is weft's (edited or not) and the
folder <git common dir>/weft/ (the script copy and the gate's cache). Another
tool's hook is left, and the call says to remove the weft line from it.