Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pre_commit/commands/migrate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def _migrate_map(contents: str) -> str:


def _preserve_style(n: ScalarNode, *, s: str) -> str:
return f'{n.style}{s}{n.style}'
style = n.style or ''
return f'{style}{s}{style}'


def _fix_stage(n: ScalarNode) -> str:
Expand Down
16 changes: 16 additions & 0 deletions tests/commands/migrate_config_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
from __future__ import annotations

from unittest import mock

import pytest
import yaml

import pre_commit.constants as C
from pre_commit.clientlib import InvalidConfigError
from pre_commit.commands.migrate_config import migrate_config
from pre_commit.yaml import yaml_compose


@pytest.fixture(autouse=True, params=['c', 'pure'])
def switch_pyyaml_impl(request):
if request.param == 'c':
yield
else:
with mock.patch.dict(
yaml_compose.keywords,
{'Loader': yaml.SafeLoader},
):
yield


def test_migrate_config_normal_format(tmpdir, capsys):
Expand Down