mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-14 17:41:45 +04:00
Add freeze config option for autoupdate command
This commit adds a new 'freeze' option to the CONFIG_SCHEMA, allowing users to set 'freeze: true' in their pre-commit configuration file. The intend are two effects, when setting `freeze: True`: * Enables freeze automatically when running `pre-commit autoupdate` (no need then anymore to specify --freeze). * Enables https://pre-commit.ci/ to freeze hooks as part of update PRs.
This commit is contained in:
parent
aa48766b88
commit
7c81f11d63
3 changed files with 15 additions and 0 deletions
|
|
@ -466,6 +466,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
cfgv.Optional('files', check_string_regex, ''),
|
||||
cfgv.Optional('exclude', check_string_regex, '^$'),
|
||||
cfgv.Optional('fail_fast', cfgv.check_bool, False),
|
||||
cfgv.Optional('freeze', cfgv.check_bool, False),
|
||||
cfgv.WarnAdditionalKeys(
|
||||
(
|
||||
'repos',
|
||||
|
|
@ -477,6 +478,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
|||
'fail_fast',
|
||||
'minimum_pre_commit_version',
|
||||
'ci',
|
||||
'freeze',
|
||||
),
|
||||
warn_unknown_keys_root,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -176,6 +176,8 @@ def autoupdate(
|
|||
if repo['repo'] not in {LOCAL, META}
|
||||
]
|
||||
|
||||
freeze = freeze or load_config(config_file)['freeze']
|
||||
|
||||
rev_infos: list[RevInfo | None] = [None] * len(config_repos)
|
||||
jobs = jobs or xargs.cpu_count() # 0 => number of cpus
|
||||
jobs = min(jobs, len(repos) or len(config_repos)) # max 1-per-thread
|
||||
|
|
|
|||
|
|
@ -139,6 +139,17 @@ def test_rev_info_update_does_not_freeze_if_already_sha(out_of_date):
|
|||
assert new_info.frozen is None
|
||||
|
||||
|
||||
def test_autoupdate_freeze_from_config(tagged, tmpdir):
|
||||
git_commit(cwd=tagged.path)
|
||||
repo = make_config_from_repo(tagged.path, rev=tagged.original_rev)
|
||||
contents = {'repos': [repo], 'freeze': True}
|
||||
cfg = tmpdir.join(C.CONFIG_FILE)
|
||||
write_config(str(tmpdir), contents)
|
||||
|
||||
assert autoupdate(str(cfg), freeze=False, tags_only=True) == 0
|
||||
assert f'rev: {tagged.head_rev} # frozen: v1.2.3' in cfg.read()
|
||||
|
||||
|
||||
def test_autoupdate_up_to_date_repo(up_to_date, tmpdir):
|
||||
contents = (
|
||||
f'repos:\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue