Let's say that I have a project repo and within it I have a packages/ folder that stores the packages that are developed under this project. Every single package is also an R project.
Now I would like to have two .pre-commit-config.yaml templates, one for the project scope and the other for the packages. The former will have R package development hooks disabled while the latter will have them enabled. The following tree represents the desired architecture.
. (project)
├── .git
├── .pre-commit-config.yaml (with DISABLED R package development hooks)
├── notebooks
├── packages
│ ├── packageA
│ │ ├── .pre-commit-config.yaml (with ENABLED R package development hooks)
│ │ ├── DESCRIPTION
│ │ └── ...
│ └── packageB
│ ├── .pre-commit-config.yaml (with ENABLED R package development hooks)
│ ├── DESCRIPTION
│ └── ...
├── README.md
└── ...
When I create a package folder inside the project directory then the package is not treated as separate git repository. If I enter the package folder (by opening the package.Rproj) and run git status
then I can also see the files from the root project folder i.e. ../../README.md.
Running precommit::use_precommit()
and here::here()
from inside the package folder will result in acknowledging the .pre-commit-conf.yaml file that lies within the package folder. git commit
action also looks at the same config file. However it looks for DESCRIPTION file (as desc-in-deps hook is enabled in the package scope) inside the project root directory. This results in the following error:
Error: No root directory found in <my/root/project/path> or its parent directories. Root criterion: contains a file `DESCRIPTION` with contents matching `^Package:
thrown by rprojroot package.
After the first commit failure, the package config is ignored. Now in second attempt (just hitting once more git commit
) the one in the project root directory will be used. Now the git commit
action will succeed because in the project root dir lies the config file that has desc-in-deps hook disabled. If I remove the yaml config from the project root directory then calling git commit
from the package workdir sticks to looking at the config in the package workdir which again results in mentioned error.
Now if I create a totally new project from RStudio navbar, and inside that project I start another R package project with checked "Create a git repository" option and plant the yaml configs as previously, then everything will work just fine, since the precommit used within the package workdir will recognize it as the root folder since it is a separate git repository.
To sum it up - at the moment it seems like using more than one precommit config yaml file in many subfolders within a single git repository results in a failure at first attempt, and automatic switch to the config that lies in the git repo root directory for the next attempt of git commit
.
Is it possible to change the functionality so that upon commiting, precommit won't execute the hooks from the perspective of the yaml config in the root directory of the git repository but from the perspective of the current working directory instead i.e. subfolder with a pacakge?