mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Merge pull request #614 from pre-commit/migrate_config_retv
pre-commit migrate-config should not return nonzero when successful
This commit is contained in:
commit
39314bfd7e
4 changed files with 5 additions and 10 deletions
|
|
@ -104,8 +104,8 @@ def _write_new_config_file(path, output):
|
||||||
|
|
||||||
def autoupdate(runner, tags_only):
|
def autoupdate(runner, tags_only):
|
||||||
"""Auto-update the pre-commit config to the latest versions of repos."""
|
"""Auto-update the pre-commit config to the latest versions of repos."""
|
||||||
|
migrate_config(runner, quiet=True)
|
||||||
retv = 0
|
retv = 0
|
||||||
retv |= migrate_config(runner, quiet=True)
|
|
||||||
output_repos = []
|
output_repos = []
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ def _is_header_line(line):
|
||||||
|
|
||||||
|
|
||||||
def migrate_config(runner, quiet=False):
|
def migrate_config(runner, quiet=False):
|
||||||
retv = 0
|
|
||||||
|
|
||||||
with io.open(runner.config_file_path) as f:
|
with io.open(runner.config_file_path) as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
|
|
||||||
|
|
@ -45,8 +43,5 @@ def migrate_config(runner, quiet=False):
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
print('Configuration has been migrated.')
|
print('Configuration has been migrated.')
|
||||||
retv = 1
|
|
||||||
elif not quiet:
|
elif not quiet:
|
||||||
print('Configuration is already migrated.')
|
print('Configuration is already migrated.')
|
||||||
|
|
||||||
return retv
|
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ def test_updates_old_format_to_new_format(tmpdir, capsys):
|
||||||
' language: script\n',
|
' language: script\n',
|
||||||
)
|
)
|
||||||
ret = autoupdate(Runner(tmpdir.strpath, C.CONFIG_FILE), tags_only=True)
|
ret = autoupdate(Runner(tmpdir.strpath, C.CONFIG_FILE), tags_only=True)
|
||||||
assert ret == 1
|
assert ret == 0
|
||||||
contents = cfg.read()
|
contents = cfg.read()
|
||||||
assert contents == (
|
assert contents == (
|
||||||
'repos:\n'
|
'repos:\n'
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ def test_migrate_config_normal_format(tmpdir, capsys):
|
||||||
' entry: ./bin/foo.sh\n'
|
' entry: ./bin/foo.sh\n'
|
||||||
' language: script\n',
|
' language: script\n',
|
||||||
)
|
)
|
||||||
assert migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE)) == 1
|
assert not migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE))
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert out == 'Configuration has been migrated.\n'
|
assert out == 'Configuration has been migrated.\n'
|
||||||
contents = cfg.read()
|
contents = cfg.read()
|
||||||
|
|
@ -61,7 +61,7 @@ def test_migrate_config_document_marker(tmpdir):
|
||||||
' entry: ./bin/foo.sh\n'
|
' entry: ./bin/foo.sh\n'
|
||||||
' language: script\n',
|
' language: script\n',
|
||||||
)
|
)
|
||||||
assert migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE)) == 1
|
assert not migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE))
|
||||||
contents = cfg.read()
|
contents = cfg.read()
|
||||||
assert contents == (
|
assert contents == (
|
||||||
'# comment\n'
|
'# comment\n'
|
||||||
|
|
@ -88,7 +88,7 @@ def test_migrate_config_list_literal(tmpdir):
|
||||||
' }]\n'
|
' }]\n'
|
||||||
'}]',
|
'}]',
|
||||||
)
|
)
|
||||||
assert migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE)) == 1
|
assert not migrate_config(Runner(tmpdir.strpath, C.CONFIG_FILE))
|
||||||
contents = cfg.read()
|
contents = cfg.read()
|
||||||
assert contents == (
|
assert contents == (
|
||||||
'repos:\n'
|
'repos:\n'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue