Skip to content

Commit

Permalink
Merge pull request PyCQA#706 from mic4ael/mnemonic-symbols-git
Browse files Browse the repository at this point in the history
Fix handling of diffs with mnemonic prefixes
  • Loading branch information
sigmavirus24 committed Dec 28, 2017
2 parents 4f5d398 + 766c78a commit 4cee4a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions testsuite/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ def test_check_diff(self):
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)

0 comments on commit 4cee4a5

Please sign in to comment.