Repository: pre-commit/pre-commit

Issue:
[RFC] Make the default of `pre-commit autoupdate` use `--tags-only`?
I find that `--tags-only` to be much better than the default.

My proposal:

- Make the `--tags-only` behaviour the default behaviour
- Make `--tags-only` a noop argument which produces a warning and does the default
- Add a `--bleeding-edge` which does the current default behaviour

@chriskuehl  thoughts?

Discussion:

Patch:
diff --git a/pre_commit/main.py b/pre_commit/main.py
index 8a77316..baaf84b 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -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':


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 23eddb5..140463b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -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)
diff --git a/tests/main_test.py b/tests/main_test.py
index 8cc6121..0425b8d 100644
--- a/tests/main_test.py
+++ b/tests/main_test.py
@@ -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()
diff --git a/tests/repository_test.py b/tests/repository_test.py
index 4cb2e4e..f91642e 100644
--- a/tests/repository_test.py
+++ b/tests/repository_test.py
@@ -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)