summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-10-25 10:31:57 +0000
committerIan Cordasco <graffatcolmingov@gmail.com>2016-10-25 10:31:57 +0000
commita90c94ab2281737c038bcdca873c6f07239eee59 (patch)
tree83c3b3e660316246eb6187ac9e7eb113b9e9f338
parent7fc699e28bda8678d60d7a152a2341781f02220b (diff)
parent941896218d477c3ec117d21dc9da45d4265269b8 (diff)
downloadflake8-a90c94ab2281737c038bcdca873c6f07239eee59.tar.gz
Merge branch 'mr/120' into 'master'
Use the lazy parameter when finding changed files with git Closes !120 See merge request !126
-rw-r--r--src/flake8/main/git.py13
-rw-r--r--tests/unit/test_git.py29
2 files changed, 37 insertions, 5 deletions
diff --git a/src/flake8/main/git.py b/src/flake8/main/git.py
index 8603f67..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', '--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)