fix missing rev

This commit is contained in:
Jam Quiceno 2021-02-19 16:13:07 -05:00
parent d827e9aa72
commit f01aad3943
3 changed files with 52 additions and 5 deletions

View file

@ -15,7 +15,8 @@ repos:
rev: 3.8.4 rev: 3.8.4
hooks: hooks:
- id: flake8 - 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 - repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.4 rev: v1.5.4
hooks: hooks:
@ -28,17 +29,20 @@ repos:
rev: v2.10.0 rev: v2.10.0
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py36-plus] args:
- --py36-plus
- repo: https://github.com/asottile/reorder_python_imports - repo: https://github.com/asottile/reorder_python_imports
rev: v2.4.0 rev: v2.4.0
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
args: [--py3-plus] args:
- --py3-plus
- repo: https://github.com/asottile/add-trailing-comma - repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0 rev: v2.1.0
hooks: hooks:
- id: add-trailing-comma - id: add-trailing-comma
args: [--py36-plus] args:
- --py36-plus
- repo: https://github.com/asottile/setup-cfg-fmt - repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.16.0 rev: v1.16.0
hooks: hooks:

View file

@ -130,6 +130,24 @@ def _write_new_config(path: str, rev_infos: List[Optional[RevInfo]]) -> None:
f.write(''.join(lines)) 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( def autoupdate(
config_file: str, config_file: str,
store: Store, store: Store,

View file

@ -12,6 +12,7 @@ from typing import Collection
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import MutableMapping from typing import MutableMapping
from typing import Optional
from typing import Sequence from typing import Sequence
from typing import Set from typing import Set
from typing import Tuple from typing import Tuple
@ -22,6 +23,7 @@ from pre_commit import color
from pre_commit import git from pre_commit import git
from pre_commit import output from pre_commit import output
from pre_commit.clientlib import load_config 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.hook import Hook
from pre_commit.languages.all import languages from pre_commit.languages.all import languages
from pre_commit.repository import all_hooks 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.store import Store
from pre_commit.util import cmd_output_b from pre_commit.util import cmd_output_b
logger = logging.getLogger('pre_commit') logger = logging.getLogger('pre_commit')
@ -325,6 +326,28 @@ def _has_unstaged_config(config_file: str) -> bool:
return retcode == 1 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( def run(
config_file: str, config_file: str,
store: Store, store: Store,
@ -387,6 +410,7 @@ def run(
exit_stack.enter_context(staged_files_only(store.directory)) exit_stack.enter_context(staged_files_only(store.directory))
config = load_config(config_file) config = load_config(config_file)
hooks = [ hooks = [
hook hook
for hook in all_hooks(config, store) 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}`', f'No hook with id `{args.hook}` in stage `{args.hook_stage}`',
) )
return 1 return 1
_solve_possible_mutable_revs(config, config_file, store)
install_hook_envs(hooks, store) install_hook_envs(hooks, store)