Skip to content

Commit 4cee4a5

Browse files
authored
Merge pull request #706 from mic4ael/mnemonic-symbols-git
Fix handling of diffs with mnemonic prefixes
2 parents 4f5d398 + 766c78a commit 4cee4a5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pycodestyle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,9 @@ def parse_udiff(diff, patterns=None, parent='.'):
15381538
rv[path].update(range(row, row + nrows))
15391539
elif line[:3] == '+++':
15401540
path = line[4:].split('\t', 1)[0]
1541-
if path[:2] == 'b/':
1541+
# Git diff will use (i)ndex, (w)ork tree, (c)ommit and (o)bject
1542+
# instead of a/b/c/d as prefixes for patches
1543+
if path[:2] in ('b/', 'w/', 'i/'):
15421544
path = path[2:]
15431545
rv[path] = set()
15441546
return dict([(os.path.join(parent, path), rows)

testsuite/test_shell.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,13 @@ def test_check_diff(self):
191191
self.assertFalse(errcode)
192192
self.assertFalse(stdout)
193193
self.assertFalse(stderr)
194+
195+
for index, diff_line in enumerate(diff_lines, 0):
196+
diff_line = diff_line.replace('a/', 'i/')
197+
diff_lines[index] = diff_line.replace('b/', 'w/')
198+
199+
self.stdin = '\n'.join(diff_lines)
200+
stdout, stderr, errcode = self.pycodestyle('--diff')
201+
self.assertFalse(errcode)
202+
self.assertFalse(stdout)
203+
self.assertFalse(stderr)

0 commit comments

Comments
 (0)