Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0d28eaa

Browse files
authoredSep 27, 2022
Merge pull request #1497 from dwapstra/git_diff_empty
Ignore empty info in diff line
2 parents b27c41a + 41003c5 commit 0d28eaa

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
 

‎git/diff.py

+3
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
574574
_, _, lines = lines.partition(":")
575575

576576
for line in lines.split("\x00:"):
577+
if not line:
578+
# The line data is empty, skip
579+
continue
577580
meta, _, path = line.partition("\x00")
578581
path = path.rstrip("\x00")
579582
a_blob_id: Optional[str]

‎test/test_diff.py

+6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ def test_diff_file_with_colon(self):
240240
output = fixture("diff_file_with_colon")
241241
res = []
242242
Diff._handle_diff_line(output, None, res)
243+
self.assertEqual(len(res), 3)
244+
245+
def test_empty_diff(self):
246+
res = []
247+
Diff._handle_diff_line(b"", None, res)
248+
self.assertEqual(res, [])
243249

244250
def test_diff_initial_commit(self):
245251
initial_commit = self.rorepo.commit("33ebe7acec14b25c5f84f35a664803fcab2f7781")

0 commit comments

Comments
 (0)
Please sign in to comment.