mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Migrate sha -> rev
This commit is contained in:
parent
184e22e81f
commit
5651c66995
19 changed files with 215 additions and 107 deletions
|
|
@ -2,6 +2,7 @@ from __future__ import print_function
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import re
|
||||
|
||||
import yaml
|
||||
from aspy.yaml import ordered_load
|
||||
|
|
@ -16,10 +17,7 @@ def _is_header_line(line):
|
|||
return (line.startswith(('#', '---')) or not line.strip())
|
||||
|
||||
|
||||
def migrate_config(runner, quiet=False):
|
||||
with io.open(runner.config_file_path) as f:
|
||||
contents = f.read()
|
||||
|
||||
def _migrate_map(contents):
|
||||
# Find the first non-header line
|
||||
lines = contents.splitlines(True)
|
||||
i = 0
|
||||
|
|
@ -39,6 +37,22 @@ def migrate_config(runner, quiet=False):
|
|||
except yaml.YAMLError:
|
||||
contents = header + 'repos:\n' + _indent(rest)
|
||||
|
||||
return contents
|
||||
|
||||
|
||||
def _migrate_sha_to_rev(contents):
|
||||
reg = re.compile(r'(\n\s+)sha:')
|
||||
return reg.sub(r'\1rev:', contents)
|
||||
|
||||
|
||||
def migrate_config(runner, quiet=False):
|
||||
with io.open(runner.config_file_path) as f:
|
||||
orig_contents = contents = f.read()
|
||||
|
||||
contents = _migrate_map(contents)
|
||||
contents = _migrate_sha_to_rev(contents)
|
||||
|
||||
if contents != orig_contents:
|
||||
with io.open(runner.config_file_path, 'w') as f:
|
||||
f.write(contents)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue