You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a {config_dir} entry placeholder to reference files next to the config
#3059
We keep one shared prek config in a central repository and run it against
several other repositories (Yocto layers) with:
prek run -c /path/to/shared/.pre-commit-config.yaml
Some hooks need their own config files, for example a .gitlint file or an .oelint-rules.json rule file. The natural place for them is next to the shared
prek config. But hooks run in the target repository, and nothing in the prek
config can refer to the directory that holds the config file.
Our current workarounds:
gitlint options are inlined as a long list of -c... arguments instead of a .gitlint file;
.oelint-rules.json is copy-pasted into every layer repository and has to be
kept in sync by hand;
a local hook uses a shell entry that walks up from $PWD until it finds the
helper script.
Proposal
Add a {config_dir} placeholder next to the existing {hook_repo} (#2602). It
expands to the absolute path of the directory that contains the config file
defining the hook.
It would follow the same rules as {hook_repo}: expanded per argument after entry is split, without a shell, only in direct command entries and language: script.
Before:
- repo: https://github.com/jorisroovers/gitlintrev: v0.19.1hooks:
- id: gitlintargs: [-ctitle-max-length.line-length=72, ..., --msg-filename]
- repo: https://github.com/priv-kweihmann/oelint-advrev: 9.10.3hooks:
- id: oelint-advargs: [--quiet, --rulefile, .oelint-rules.json] # a copy in every layer repo
The pinned remote hooks stay as they are. Only their entry is overridden.
Alternatives considered
A PREK_CONFIG_DIR environment variable for hooks. This would work with shell: bash and entry: exec tool --config "$PREK_CONFIG_DIR/..." "$@", but
every hook then needs a shell wrapper. A placeholder fits the existing {hook_repo} design and needs no shell.
A dedicated hook repo for the shared hooks and their config files. This
works today with {hook_repo}, but each tool's hook must be redefined there,
and every rule change needs a release and a rev bump. {config_dir} keeps
the config files next to the config that uses them and keeps the upstream hook
definitions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Use case
We keep one shared prek config in a central repository and run it against
several other repositories (Yocto layers) with:
Some hooks need their own config files, for example a
.gitlintfile or an.oelint-rules.jsonrule file. The natural place for them is next to the sharedprek config. But hooks run in the target repository, and nothing in the prek
config can refer to the directory that holds the config file.
Our current workarounds:
-c...arguments instead of a.gitlintfile;.oelint-rules.jsonis copy-pasted into every layer repository and has to bekept in sync by hand;
shellentry that walks up from$PWDuntil it finds thehelper script.
Proposal
Add a
{config_dir}placeholder next to the existing{hook_repo}(#2602). Itexpands to the absolute path of the directory that contains the config file
defining the hook.
It would follow the same rules as
{hook_repo}: expanded per argument afterentryis split, without a shell, only in direct command entries andlanguage: script.Before:
After:
The pinned remote hooks stay as they are. Only their
entryis overridden.Alternatives considered
PREK_CONFIG_DIRenvironment variable for hooks. This would work withshell: bashandentry: exec tool --config "$PREK_CONFIG_DIR/..." "$@", butevery hook then needs a shell wrapper. A placeholder fits the existing
{hook_repo}design and needs no shell.works today with
{hook_repo}, but each tool's hook must be redefined there,and every rule change needs a release and a
revbump.{config_dir}keepsthe config files next to the config that uses them and keeps the upstream hook
definitions.
!Env). This makesconfigs depend on the user's environment, which was a concern in Support loading env vars from shell, .env, and .envrc, and allow env to reference names only #1329. I
proposed this to pre-commit first and it was declined.
Open questions
args?{hook_repo}currently does not, andentryis enough for the cases above.Hooks that use the placeholder would set
minimum_prek_version, since upstreampre-commit would pass it through literally.
I'm happy to send a PR with docs and a test if this direction sounds good.
All reactions