Merge pull request #529 from pre-commit/tags_only_default

Make autoupdate --tags-only the default, add --bleeding-edge
This commit is contained in:
Anthony Sottile
2017-05-05 14:49:15 -07:00
committed by GitHub
4 changed files with 28 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import unicode_literals
import argparse
import logging
import os
import sys
@@ -20,6 +21,8 @@ from pre_commit.logging_handler import add_logging_handler
from pre_commit.runner import Runner
logger = logging.getLogger('pre_commit')
# https://github.com/pre-commit/pre-commit/issues/217
# 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
@@ -117,7 +120,14 @@ def main(argv=None):
_add_color_option(autoupdate_parser)
_add_config_option(autoupdate_parser)
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.')
@@ -209,7 +219,9 @@ def main(argv=None):
elif args.command == 'clean':
return clean(runner)
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':
return run(runner, args)
elif args.command == 'sample-config':

View File

@@ -186,3 +186,12 @@ def cap_out():
with mock.patch.object(output, 'write', write):
with mock.patch.object(output, 'write_line', write_line):
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)

View File

@@ -127,3 +127,8 @@ def test_expected_fatal_error_no_git_repo(
'Is it installed, and are you in a Git repository directory?\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()

View File

@@ -2,7 +2,6 @@ from __future__ import absolute_import
from __future__ import unicode_literals
import io
import logging
import os.path
import re
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"
@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):
path = make_repo(tempdir_factory, 'script_hooks_repo')
config = make_config_from_repo(path)