summaryrefslogtreecommitdiffstats
path: root/pre_commit/commands/autoupdate.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-06-14 09:11:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-06-14 09:11:21 +0000
commitcc9f06b22c7665893e6958f7518a9e8d258e7d98 (patch)
tree19c3ef54ef886a32df2f3ed7be2f694d77b50bfc /pre_commit/commands/autoupdate.py
parentAdding upstream version 2.3.0. (diff)
downloadpre-commit-cc9f06b22c7665893e6958f7518a9e8d258e7d98.tar.xz
pre-commit-cc9f06b22c7665893e6958f7518a9e8d258e7d98.zip
Adding upstream version 2.5.1.upstream/2.5.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/commands/autoupdate.py')
-rw-r--r--pre_commit/commands/autoupdate.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py
index 8c9fdd7..87f6d53 100644
--- a/pre_commit/commands/autoupdate.py
+++ b/pre_commit/commands/autoupdate.py
@@ -84,7 +84,9 @@ def _check_hooks_still_exist_at_rev(
)
-REV_LINE_RE = re.compile(r'^(\s+)rev:(\s*)([^\s#]+)(.*)(\r?\n)$', re.DOTALL)
+REV_LINE_RE = re.compile(
+ r'^(\s+)rev:(\s*)([\'"]?)([^\s#]+)(.*)(\r?\n)$', re.DOTALL,
+)
def _original_lines(
@@ -116,15 +118,15 @@ def _write_new_config(path: str, rev_infos: List[Optional[RevInfo]]) -> None:
continue
match = REV_LINE_RE.match(lines[idx])
assert match is not None
- new_rev_s = yaml_dump({'rev': rev_info.rev})
+ new_rev_s = yaml_dump({'rev': rev_info.rev}, default_style=match[3])
new_rev = new_rev_s.split(':', 1)[1].strip()
if rev_info.frozen is not None:
comment = f' # frozen: {rev_info.frozen}'
- elif match[4].strip().startswith('# frozen:'):
+ elif match[5].strip().startswith('# frozen:'):
comment = ''
else:
- comment = match[4]
- lines[idx] = f'{match[1]}rev:{match[2]}{new_rev}{comment}{match[5]}'
+ comment = match[5]
+ lines[idx] = f'{match[1]}rev:{match[2]}{new_rev}{comment}{match[6]}'
with open(path, 'w', newline='') as f:
f.write(''.join(lines))