Skip to content

Commit 35caf11

Browse files
committed
clear 'frozen: ...' comment if autoupdate unfreezes
1 parent cd57ba9 commit 35caf11

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pre_commit/commands/autoupdate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def _write_new_config(path, rev_infos):
108108
new_rev_s = ordered_dump({'rev': rev_info.rev}, **C.YAML_DUMP_KWARGS)
109109
new_rev = new_rev_s.split(':', 1)[1].strip()
110110
if rev_info.frozen is not None:
111-
comment = ' # {}'.format(rev_info.frozen)
111+
comment = ' # frozen: {}'.format(rev_info.frozen)
112+
elif match.group(4).strip().startswith('# frozen:'):
113+
comment = ''
112114
else:
113115
comment = match.group(4)
114116
lines[idx] = REV_LINE_FMT.format(

tests/commands/autoupdate_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,14 @@ def test_autoupdate_freeze(tagged, in_tmpdir, store):
312312

313313
assert autoupdate(C.CONFIG_FILE, store, freeze=True, tags_only=False) == 0
314314
with open(C.CONFIG_FILE) as f:
315-
expected = 'rev: {} # v1.2.3'.format(tagged.head_rev)
315+
expected = 'rev: {} # frozen: v1.2.3'.format(tagged.head_rev)
316316
assert expected in f.read()
317317

318+
# if we un-freeze it should remove the frozen comment
319+
assert autoupdate(C.CONFIG_FILE, store, freeze=False, tags_only=False) == 0
320+
with open(C.CONFIG_FILE) as f:
321+
assert 'rev: v1.2.3\n' in f.read()
322+
318323

319324
def test_autoupdate_tags_only(tagged, in_tmpdir, store):
320325
# add some commits after the tag

0 commit comments

Comments
 (0)