mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 02:21:46 +04:00
fix missing rev
This commit is contained in:
parent
d827e9aa72
commit
f01aad3943
3 changed files with 52 additions and 5 deletions
|
|
@ -15,7 +15,8 @@ repos:
|
|||
rev: 3.8.4
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [flake8-typing-imports==1.10.0]
|
||||
additional_dependencies:
|
||||
- flake8-typing-imports==1.10.0
|
||||
- repo: https://github.com/pre-commit/mirrors-autopep8
|
||||
rev: v1.5.4
|
||||
hooks:
|
||||
|
|
@ -28,17 +29,20 @@ repos:
|
|||
rev: v2.10.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py36-plus]
|
||||
args:
|
||||
- --py36-plus
|
||||
- repo: https://github.com/asottile/reorder_python_imports
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
args: [--py3-plus]
|
||||
args:
|
||||
- --py3-plus
|
||||
- repo: https://github.com/asottile/add-trailing-comma
|
||||
rev: v2.1.0
|
||||
hooks:
|
||||
- id: add-trailing-comma
|
||||
args: [--py36-plus]
|
||||
args:
|
||||
- --py36-plus
|
||||
- repo: https://github.com/asottile/setup-cfg-fmt
|
||||
rev: v1.16.0
|
||||
hooks:
|
||||
|
|
|
|||
|
|
@ -130,6 +130,24 @@ def _write_new_config(path: str, rev_infos: List[Optional[RevInfo]]) -> None:
|
|||
f.write(''.join(lines))
|
||||
|
||||
|
||||
def mutable_rev_fix(
|
||||
config_file: str,
|
||||
repos: List[Optional[Dict[str, Any]]],
|
||||
) -> None:
|
||||
rev_infos: List[Optional[RevInfo]] = []
|
||||
for repo_config in repos:
|
||||
if not repo_config:
|
||||
rev_infos.append(None)
|
||||
continue
|
||||
info = RevInfo.from_config(repo_config)
|
||||
updated_info = info.update(tags_only=True, freeze=False)
|
||||
msg = f"{repo_config['repo']}: \
|
||||
updating {info.rev} -> {updated_info.rev}."
|
||||
output.write_line(msg)
|
||||
rev_infos.append(updated_info)
|
||||
_write_new_config(config_file, rev_infos)
|
||||
|
||||
|
||||
def autoupdate(
|
||||
config_file: str,
|
||||
store: Store,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from typing import Collection
|
|||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import MutableMapping
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
from typing import Set
|
||||
from typing import Tuple
|
||||
|
|
@ -22,6 +23,7 @@ from pre_commit import color
|
|||
from pre_commit import git
|
||||
from pre_commit import output
|
||||
from pre_commit.clientlib import load_config
|
||||
from pre_commit.commands.autoupdate import mutable_rev_fix
|
||||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages.all import languages
|
||||
from pre_commit.repository import all_hooks
|
||||
|
|
@ -30,7 +32,6 @@ from pre_commit.staged_files_only import staged_files_only
|
|||
from pre_commit.store import Store
|
||||
from pre_commit.util import cmd_output_b
|
||||
|
||||
|
||||
logger = logging.getLogger('pre_commit')
|
||||
|
||||
|
||||
|
|
@ -325,6 +326,28 @@ def _has_unstaged_config(config_file: str) -> bool:
|
|||
return retcode == 1
|
||||
|
||||
|
||||
def _solve_possible_mutable_revs(
|
||||
config: Dict[str, Any],
|
||||
config_file: str,
|
||||
store: Store,
|
||||
) -> None:
|
||||
|
||||
if 'repos' not in config:
|
||||
return None
|
||||
|
||||
to_update: List[Optional[Dict[str, Any]]] = []
|
||||
for repo in config['repos']:
|
||||
if 'rev' in repo and repo['rev'] == '':
|
||||
to_update.append(repo)
|
||||
else:
|
||||
to_update.append(None)
|
||||
if not all(repo is None for repo in to_update):
|
||||
mutable_rev_fix(
|
||||
config_file,
|
||||
repos=to_update,
|
||||
)
|
||||
|
||||
|
||||
def run(
|
||||
config_file: str,
|
||||
store: Store,
|
||||
|
|
@ -387,6 +410,7 @@ def run(
|
|||
exit_stack.enter_context(staged_files_only(store.directory))
|
||||
|
||||
config = load_config(config_file)
|
||||
|
||||
hooks = [
|
||||
hook
|
||||
for hook in all_hooks(config, store)
|
||||
|
|
@ -399,6 +423,7 @@ def run(
|
|||
f'No hook with id `{args.hook}` in stage `{args.hook_stage}`',
|
||||
)
|
||||
return 1
|
||||
_solve_possible_mutable_revs(config, config_file, store)
|
||||
|
||||
install_hook_envs(hooks, store)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue