mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make autoupdate --tags-only the default, add --bleeding-edge
This commit is contained in:
parent
1be4e4f82e
commit
918179849d
4 changed files with 28 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -20,6 +21,8 @@ from pre_commit.logging_handler import add_logging_handler
|
||||||
from pre_commit.runner import Runner
|
from pre_commit.runner import Runner
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('pre_commit')
|
||||||
|
|
||||||
# https://github.com/pre-commit/pre-commit/issues/217
|
# https://github.com/pre-commit/pre-commit/issues/217
|
||||||
# On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`
|
# On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`
|
||||||
# to install packages to the wrong place. We don't want anything to deal with
|
# to install packages to the wrong place. We don't want anything to deal with
|
||||||
|
|
@ -117,7 +120,14 @@ def main(argv=None):
|
||||||
_add_color_option(autoupdate_parser)
|
_add_color_option(autoupdate_parser)
|
||||||
_add_config_option(autoupdate_parser)
|
_add_config_option(autoupdate_parser)
|
||||||
autoupdate_parser.add_argument(
|
autoupdate_parser.add_argument(
|
||||||
'--tags-only', action='store_true', help='Update to tags only.',
|
'--tags-only', action='store_true', help='LEGACY: for compatibility',
|
||||||
|
)
|
||||||
|
autoupdate_parser.add_argument(
|
||||||
|
'--bleeding-edge', action='store_true',
|
||||||
|
help=(
|
||||||
|
'Update to the bleeding edge of `master` instead of the latest '
|
||||||
|
'tagged version (the default behavior).'
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
run_parser = subparsers.add_parser('run', help='Run hooks.')
|
run_parser = subparsers.add_parser('run', help='Run hooks.')
|
||||||
|
|
@ -209,7 +219,9 @@ def main(argv=None):
|
||||||
elif args.command == 'clean':
|
elif args.command == 'clean':
|
||||||
return clean(runner)
|
return clean(runner)
|
||||||
elif args.command == 'autoupdate':
|
elif args.command == 'autoupdate':
|
||||||
return autoupdate(runner, args.tags_only)
|
if args.tags_only:
|
||||||
|
logger.warning('--tags-only is the default')
|
||||||
|
return autoupdate(runner, tags_only=not args.bleeding_edge)
|
||||||
elif args.command == 'run':
|
elif args.command == 'run':
|
||||||
return run(runner, args)
|
return run(runner, args)
|
||||||
elif args.command == 'sample-config':
|
elif args.command == 'sample-config':
|
||||||
|
|
|
||||||
|
|
@ -186,3 +186,12 @@ def cap_out():
|
||||||
with mock.patch.object(output, 'write', write):
|
with mock.patch.object(output, 'write', write):
|
||||||
with mock.patch.object(output, 'write_line', write_line):
|
with mock.patch.object(output, 'write_line', write_line):
|
||||||
yield Fixture(stream)
|
yield Fixture(stream)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def fake_log_handler():
|
||||||
|
handler = mock.Mock(level=logging.INFO)
|
||||||
|
logger = logging.getLogger('pre_commit')
|
||||||
|
logger.addHandler(handler)
|
||||||
|
yield handler
|
||||||
|
logger.removeHandler(handler)
|
||||||
|
|
|
||||||
|
|
@ -127,3 +127,8 @@ def test_expected_fatal_error_no_git_repo(
|
||||||
'Is it installed, and are you in a Git repository directory?\n'
|
'Is it installed, and are you in a Git repository directory?\n'
|
||||||
'Check the log at ~/.pre-commit/pre-commit.log\n'
|
'Check the log at ~/.pre-commit/pre-commit.log\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_warning_on_tags_only(mock_commands, cap_out):
|
||||||
|
main.main(('autoupdate', '--tags-only'))
|
||||||
|
assert '--tags-only is the default' in cap_out.get()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import logging
|
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -680,15 +679,6 @@ def test_local_python_repo(store):
|
||||||
assert ret[1].replace(b'\r\n', b'\n') == b"['filename']\nHello World\n"
|
assert ret[1].replace(b'\r\n', b'\n') == b"['filename']\nHello World\n"
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
|
||||||
def fake_log_handler():
|
|
||||||
handler = mock.Mock(level=logging.INFO)
|
|
||||||
logger = logging.getLogger('pre_commit')
|
|
||||||
logger.addHandler(handler)
|
|
||||||
yield handler
|
|
||||||
logger.removeHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
||||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue