Maintain scalar quoting style when autoupdate re-writes rev

If rev is wrapped in single or double quotes (e.g. due to a yamllint quoted-strings rule), when
re-writing the rev to update it, honour the existing quotation style
This commit is contained in:
Marc Jay 2020-05-05 00:42:54 +01:00 committed by Anthony Sottile
parent f455312944
commit 98d8a3d60f
3 changed files with 29 additions and 6 deletions

View file

@ -474,3 +474,23 @@ def test_updates_old_format_to_new_format(tmpdir, capsys, store):
)
out, _ = capsys.readouterr()
assert out == 'Configuration has been migrated.\n'
def test_maintains_rev_quoting_style(tmpdir, out_of_date, store):
fmt = (
'repos:\n'
'- repo: {path}\n'
' rev: "{rev}"\n'
' hooks:\n'
' - id: foo\n'
'- repo: {path}\n'
" rev: '{rev}'\n"
' hooks:\n'
' - id: foo\n'
)
cfg = tmpdir.join(C.CONFIG_FILE)
cfg.write(fmt.format(path=out_of_date.path, rev=out_of_date.original_rev))
assert autoupdate(str(cfg), store, freeze=False, tags_only=False) == 0
expected = fmt.format(path=out_of_date.path, rev=out_of_date.head_rev)
assert cfg.read() == expected