diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-10-24 18:29:45 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-10-25 05:25:44 -0500 |
| commit | 941896218d477c3ec117d21dc9da45d4265269b8 (patch) | |
| tree | 83c3b3e660316246eb6187ac9e7eb113b9e9f338 | |
| parent | 0285359a1418def10b4dbd3c94af7855bad54eca (diff) | |
| download | flake8-941896218d477c3ec117d21dc9da45d4265269b8.tar.gz | |
Change how we apply lazy to the git hook
| -rw-r--r-- | src/flake8/main/git.py | 13 | ||||
| -rw-r--r-- | tests/unit/test_git.py | 29 |
2 files changed, 37 insertions, 5 deletions
diff --git a/src/flake8/main/git.py b/src/flake8/main/git.py index 642ff38..d0c87d3 100644 --- a/src/flake8/main/git.py +++ b/src/flake8/main/git.py @@ -140,11 +140,14 @@ def make_temporary_directory_from(destination, directory): def find_modified_files(lazy): - diff_index = piped_process( - ['git', 'diff-index', '' if lazy else '--cached', '--name-only', - '--diff-filter=ACMRTUXB', 'HEAD'], - ) - + diff_index_cmd = [ + 'git', 'diff-index', '--cached', '--name-only', + '--diff-filter=ACMRTUXB', 'HEAD' + ] + if lazy: + diff_index_cmd.remove('--cached') + + diff_index = piped_process(diff_index_cmd) (stdout, _) = diff_index.communicate() stdout = to_text(stdout) return stdout.splitlines() diff --git a/tests/unit/test_git.py b/tests/unit/test_git.py new file mode 100644 index 0000000..24d4b5b --- /dev/null +++ b/tests/unit/test_git.py @@ -0,0 +1,29 @@ +"""Tests around functionality in the git integration.""" +import mock +import pytest + +from flake8.main import git + + +@pytest.mark.parametrize('lazy', [True, False]) +def test_find_modified_files(lazy): + """Confirm our logic for listing modified files.""" + if lazy: + # Here --cached is missing + call = [ + 'git', 'diff-index', '--name-only', '--diff-filter=ACMRTUXB', + 'HEAD' + ] + else: + call = [ + 'git', 'diff-index', '--cached', '--name-only', + '--diff-filter=ACMRTUXB', 'HEAD' + ] + mocked_popen = mock.Mock() + mocked_popen.communicate.return_value = ('', '') + + with mock.patch('flake8.main.git.piped_process') as piped_process: + piped_process.return_value = mocked_popen + git.find_modified_files(lazy) + + piped_process.assert_called_once_with(call) |
