Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Commit ac492e1

Browse files
committed
Fix crashing on files with no changes
If a file only has mode differences, but no content difference, we do not have access through GitPython to find out the filenames. gitpython-developers/GitPython#266 has been submitted to correct that, but in the mean time, display "Unknown File" to avoid crashing. Change-Id: Ic935f9737ae3978a7a639408c24f166c76a2c999 Story: 2000027
1 parent 121df15 commit ac492e1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gertty/gitrepo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ def __init__(self, old, new):
112112
self.deleted_file = False
113113
self.a_blob = CommitBlob()
114114
self.b_blob = CommitBlob()
115+
self.a_path = self.a_blob.path
116+
self.b_path = self.b_blob.path
115117
self.diff = ''.join(difflib.unified_diff(
116118
self.decorateMessage(old), self.decorateMessage(new),
117119
fromfile="/a/COMMIT_MSG", tofile="/b/COMMIT_MSG"))
@@ -166,8 +168,8 @@ class DiffChangedChunk(DiffChunk):
166168

167169
class DiffFile(object):
168170
def __init__(self):
169-
self.newname = None
170-
self.oldname = None
171+
self.newname = 'Unknown File'
172+
self.oldname = 'Unknown File'
171173
self.chunks = []
172174
self.current_chunk = None
173175
self.old_lineno = 0
@@ -377,6 +379,10 @@ def diff(self, old, new, context=10000, show_old_commit=False):
377379
f.oldname = diff_context.a_blob.path
378380
if diff_context.b_blob:
379381
f.newname = diff_context.b_blob.path
382+
# TODO(jeblair): if/when https://github.com/gitpython-developers/GitPython/pull/266 merges,
383+
# remove above 4 lines and replace with these two:
384+
# f.oldname = diff_context.a_path
385+
# f.newname = diff_context.b_path
380386
if diff_context.new_file:
381387
f.oldname = 'Empty file'
382388
if diff_context.deleted_file:

0 commit comments

Comments
 (0)