summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Kolodziejski <crossner90@gmail.com>2017-12-06 21:34:46 +0100
committerMichal Kolodziejski <crossner90@gmail.com>2017-12-27 10:56:10 +0100
commit766c78a01d9ef8908f8254d9e8a19cac28c8d048 (patch)
tree450756bc1e00a1319d95c05609194110350b31e1
parent4f5d398f9256727ad8fd7f67c45ea60a8fad5a4a (diff)
downloadpep8-766c78a01d9ef8908f8254d9e8a19cac28c8d048.tar.gz
Fix handling of diffs with mnemonic prefixes
-rwxr-xr-xpycodestyle.py4
-rw-r--r--testsuite/test_shell.py10
2 files changed, 13 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 1b06691..eb9ff63 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1538,7 +1538,9 @@ def parse_udiff(diff, patterns=None, parent='.'):
rv[path].update(range(row, row + nrows))
elif line[:3] == '+++':
path = line[4:].split('\t', 1)[0]
- if path[:2] == 'b/':
+ # Git diff will use (i)ndex, (w)ork tree, (c)ommit and (o)bject
+ # instead of a/b/c/d as prefixes for patches
+ if path[:2] in ('b/', 'w/', 'i/'):
path = path[2:]
rv[path] = set()
return dict([(os.path.join(parent, path), rows)
diff --git a/testsuite/test_shell.py b/testsuite/test_shell.py
index a80c875..7ada1a4 100644
--- a/testsuite/test_shell.py
+++ b/testsuite/test_shell.py
@@ -191,3 +191,13 @@ class ShellTestCase(unittest.TestCase):
self.assertFalse(errcode)
self.assertFalse(stdout)
self.assertFalse(stderr)
+
+ for index, diff_line in enumerate(diff_lines, 0):
+ diff_line = diff_line.replace('a/', 'i/')
+ diff_lines[index] = diff_line.replace('b/', 'w/')
+
+ self.stdin = '\n'.join(diff_lines)
+ stdout, stderr, errcode = self.pycodestyle('--diff')
+ self.assertFalse(errcode)
+ self.assertFalse(stdout)
+ self.assertFalse(stderr)