From 3e2b1862ad9c2035fd623171c6bfbae32c9aaaad Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 13 Apr 2014 20:04:58 -0700 Subject: [PATCH] Don't stash with --all-files. Closes #68. --- pre_commit/commands.py | 2 +- pre_commit/run.py | 2 +- tests/commands_test.py | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pre_commit/commands.py b/pre_commit/commands.py index 832bc664..ac9d4487 100644 --- a/pre_commit/commands.py +++ b/pre_commit/commands.py @@ -234,7 +234,7 @@ def run(runner, args, write=sys.stdout.write): logger.addHandler(LoggingHandler(args.color, write=write)) logger.setLevel(logging.INFO) - if args.no_stash: + if args.no_stash or args.all_files: ctx = noop_context() else: ctx = staged_files_only(runner.cmd_runner) diff --git a/pre_commit/run.py b/pre_commit/run.py index d4f339d8..706d68dd 100644 --- a/pre_commit/run.py +++ b/pre_commit/run.py @@ -25,7 +25,7 @@ def run(argv): run_parser.add_argument('hook', nargs='?', help='A single hook-id to run') run_parser.add_argument( '--all-files', '-a', action='store_true', default=False, - help='Run on all the files in the repo.', + help='Run on all the files in the repo. Implies --no-stash.', ) run_parser.add_argument( '--color', default='auto', type=color.use_color, diff --git a/tests/commands_test.py b/tests/commands_test.py index d4fd73a6..ae4e3b4c 100644 --- a/tests/commands_test.py +++ b/tests/commands_test.py @@ -252,18 +252,26 @@ def test_run(repo_with_passing_hook, options, outputs, expected_ret, stage): _test_run(repo_with_passing_hook, options, outputs, expected_ret, stage) -@pytest.mark.parametrize('no_stash', (True, False)) -def test_no_stash(repo_with_passing_hook, no_stash): +@pytest.mark.parametrize( + ('no_stash', 'all_files', 'expect_stash'), + ( + (True, True, False), + (True, False, False), + (False, True, False), + (False, False, True), + ), +) +def test_no_stash(repo_with_passing_hook, no_stash, all_files, expect_stash): stage_a_file() # Make unstaged changes with open('foo.py', 'w') as foo_file: foo_file.write('import os\n') - args = _get_opts(no_stash=no_stash) + args = _get_opts(no_stash=no_stash, all_files=all_files) ret, printed = _do_run(repo_with_passing_hook, args) assert ret == 0 warning_msg = '[WARNING] Unstaged files detected.' - if no_stash: - assert warning_msg not in printed - else: + if expect_stash: assert warning_msg in printed + else: + assert warning_msg not in printed