Skip to content

Commit 5d43b05

Browse files
authored
Merge pull request pre-commit#529 from pre-commit/tags_only_default
Make autoupdate --tags-only the default, add --bleeding-edge
2 parents 1be4e4f + 9181798 commit 5d43b05

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

pre_commit/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import unicode_literals
22

33
import argparse
4+
import logging
45
import os
56
import sys
67

@@ -20,6 +21,8 @@
2021
from pre_commit.runner import Runner
2122

2223

24+
logger = logging.getLogger('pre_commit')
25+
2326
# https://github.com/pre-commit/pre-commit/issues/217
2427
# On OSX, making a virtualenv using pyvenv at . causes `virtualenv` and `pip`
2528
# to install packages to the wrong place. We don't want anything to deal with
@@ -117,7 +120,14 @@ def main(argv=None):
117120
_add_color_option(autoupdate_parser)
118121
_add_config_option(autoupdate_parser)
119122
autoupdate_parser.add_argument(
120-
'--tags-only', action='store_true', help='Update to tags only.',
123+
'--tags-only', action='store_true', help='LEGACY: for compatibility',
124+
)
125+
autoupdate_parser.add_argument(
126+
'--bleeding-edge', action='store_true',
127+
help=(
128+
'Update to the bleeding edge of `master` instead of the latest '
129+
'tagged version (the default behavior).'
130+
),
121131
)
122132

123133
run_parser = subparsers.add_parser('run', help='Run hooks.')
@@ -209,7 +219,9 @@ def main(argv=None):
209219
elif args.command == 'clean':
210220
return clean(runner)
211221
elif args.command == 'autoupdate':
212-
return autoupdate(runner, args.tags_only)
222+
if args.tags_only:
223+
logger.warning('--tags-only is the default')
224+
return autoupdate(runner, tags_only=not args.bleeding_edge)
213225
elif args.command == 'run':
214226
return run(runner, args)
215227
elif args.command == 'sample-config':

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,12 @@ def cap_out():
186186
with mock.patch.object(output, 'write', write):
187187
with mock.patch.object(output, 'write_line', write_line):
188188
yield Fixture(stream)
189+
190+
191+
@pytest.yield_fixture
192+
def fake_log_handler():
193+
handler = mock.Mock(level=logging.INFO)
194+
logger = logging.getLogger('pre_commit')
195+
logger.addHandler(handler)
196+
yield handler
197+
logger.removeHandler(handler)

tests/main_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@ def test_expected_fatal_error_no_git_repo(
127127
'Is it installed, and are you in a Git repository directory?\n'
128128
'Check the log at ~/.pre-commit/pre-commit.log\n'
129129
)
130+
131+
132+
def test_warning_on_tags_only(mock_commands, cap_out):
133+
main.main(('autoupdate', '--tags-only'))
134+
assert '--tags-only is the default' in cap_out.get()

tests/repository_test.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import unicode_literals
33

44
import io
5-
import logging
65
import os.path
76
import re
87
import shutil
@@ -680,15 +679,6 @@ def test_local_python_repo(store):
680679
assert ret[1].replace(b'\r\n', b'\n') == b"['filename']\nHello World\n"
681680

682681

683-
@pytest.yield_fixture
684-
def fake_log_handler():
685-
handler = mock.Mock(level=logging.INFO)
686-
logger = logging.getLogger('pre_commit')
687-
logger.addHandler(handler)
688-
yield handler
689-
logger.removeHandler(handler)
690-
691-
692682
def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
693683
path = make_repo(tempdir_factory, 'script_hooks_repo')
694684
config = make_config_from_repo(path)

0 commit comments

Comments
 (0)