Skip to content

Commit 923b3fd

Browse files
authored
Fix empty file error (#248)
* repro * bug fix
1 parent d8606b1 commit 923b3fd

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

testdata/empty/left/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('something here')

testdata/empty/right/__init__.py

Whitespace-only changes.

webdiff/diff.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ def fast_num_lines(path: str) -> int:
4242
# See https://stackoverflow.com/q/9629179/388951 for the idea to use a Unix command.
4343
# Unfortunately `wc -l` ignores the last line if there is no trailing newline. So
4444
# instead, see https://stackoverflow.com/a/38870057/388951
45-
return int(subprocess.check_output(['grep', '-c', '', path]))
45+
try:
46+
return int(subprocess.check_output(['grep', '-c', '', path]))
47+
except subprocess.CalledProcessError as e:
48+
if e.returncode == 1:
49+
return 0 # grep -c returns an error code if there are no matches
50+
raise
4651

4752

4853
def get_diff_ops(

0 commit comments

Comments
 (0)