mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Merge pull request #933 from jessebona/patch-1
Fix crash on `pre-commit migrate-config` when configuration is empty
This commit is contained in:
commit
7e2ad215c2
2 changed files with 12 additions and 1 deletions
|
|
@ -21,7 +21,8 @@ def _migrate_map(contents):
|
|||
# Find the first non-header line
|
||||
lines = contents.splitlines(True)
|
||||
i = 0
|
||||
while _is_header_line(lines[i]):
|
||||
# Only loop on non empty configuration file
|
||||
while i < len(lines) and _is_header_line(lines[i]):
|
||||
i += 1
|
||||
|
||||
header = ''.join(lines[:i])
|
||||
|
|
|
|||
|
|
@ -147,3 +147,13 @@ def test_migrate_config_sha_to_rev(tmpdir):
|
|||
' rev: v1.2.0\n'
|
||||
' hooks: []\n'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('contents', ('', '\n'))
|
||||
def test_empty_configuration_file_user_error(tmpdir, contents):
|
||||
cfg = tmpdir.join(C.CONFIG_FILE)
|
||||
cfg.write(contents)
|
||||
with tmpdir.as_cwd():
|
||||
assert not migrate_config(C.CONFIG_FILE)
|
||||
# even though the config is invalid, this should be a noop
|
||||
assert cfg.read() == contents
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue