mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 18:41:46 +04:00
hook: enable calling out of tree entries
in the following setup
├── common
│ ├── .pre-commit-config.yaml
│ ├── script1.sh
│ └── script-config
├── repo1
│ └── code_file
└── repo2
└── code_file
a common configuration from 'common' folder will be installed using an
absolute path to repo1 and repo2.
As local tools needs to be run (script1.sh with its
configuration script-config) we need to pass the path to common
somehow into the hook cmdline.
Add support for a template variable %CONFIG_BASEPATH% which
is automatically expanded to the configuration directory when
pre-commit run is called
This helps to create a single source of truth setup, while still
keeping the possibility to call non public tools and configurations
Signed-off-by: Konrad Weihmann <kweihmann@outlook.com>
This commit is contained in:
parent
e1ce4c0bf3
commit
91f0344b08
3 changed files with 46 additions and 1 deletions
|
|
@ -265,6 +265,39 @@ def test_global_exclude(cap_out, store, in_git_dir):
|
|||
assert printed.endswith(b'\n\n.pre-commit-config.yaml\nbar.py\n\n')
|
||||
|
||||
|
||||
def test_global_hook_expand(cap_out, store, in_git_dir):
|
||||
config = {
|
||||
'repos': [
|
||||
{
|
||||
'repo': 'local',
|
||||
'hooks': [
|
||||
{
|
||||
'id': 'foo',
|
||||
'language': 'script',
|
||||
'name': 'bar',
|
||||
'entry': '%CONFIG_BASEPATH%/script',
|
||||
'args': ['%CONFIG_BASEPATH%'],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
write_config('.', config)
|
||||
|
||||
open('foo.py', 'a').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
opts = run_opts(verbose=False)
|
||||
ret, printed = _do_run(cap_out, store, str(in_git_dir), opts)
|
||||
# script doesn't exist so this needs to fail
|
||||
assert ret != 0
|
||||
|
||||
# %CONFIG_BASEPATH% is properly expanded
|
||||
assert b'%CONFIG_BASEPATH%' not in printed
|
||||
if sys.platform != 'win32':
|
||||
# on windows path separator would look different
|
||||
assert f'{in_git_dir}/script'.encode() in printed
|
||||
|
||||
|
||||
def test_global_files(cap_out, store, in_git_dir):
|
||||
config = {
|
||||
'files': r'^bar\.py$',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue