|
107 | 107 | delete mode 100644 c/d
|
108 | 108 | """
|
109 | 109 |
|
| 110 | +TEXT_BLOB1 = """Common header of the file |
| 111 | +Blob 1 line 1 |
| 112 | +Common middle line 1 |
| 113 | +Common middle line 2 |
| 114 | +Common middle line 3 |
| 115 | +Blob 1 line 2 |
| 116 | +Common footer of the file |
| 117 | +""" |
| 118 | + |
| 119 | +TEXT_BLOB2 = """Common header of the file |
| 120 | +Blob 2 line 1 |
| 121 | +Common middle line 1 |
| 122 | +Common middle line 2 |
| 123 | +Common middle line 3 |
| 124 | +Blob 2 line 2 |
| 125 | +Common footer of the file |
| 126 | +""" |
| 127 | + |
| 128 | +PATCH_BLOBS_DEFAULT = """diff --git a/ b/ |
| 129 | +index 0b5ac93..ddfdbcc 100644 |
| 130 | +--- a/ |
| 131 | ++++ b/ |
| 132 | +@@ -1,7 +1,7 @@ |
| 133 | + Common header of the file |
| 134 | +-Blob 1 line 1 |
| 135 | ++Blob 2 line 1 |
| 136 | + Common middle line 1 |
| 137 | + Common middle line 2 |
| 138 | + Common middle line 3 |
| 139 | +-Blob 1 line 2 |
| 140 | ++Blob 2 line 2 |
| 141 | + Common footer of the file |
| 142 | +""" |
| 143 | + |
| 144 | +PATCH_BLOBS_NO_LEEWAY = """diff --git a/ b/ |
| 145 | +index 0b5ac93..ddfdbcc 100644 |
| 146 | +--- a/ |
| 147 | ++++ b/ |
| 148 | +@@ -2 +2 @@ Common header of the file |
| 149 | +-Blob 1 line 1 |
| 150 | ++Blob 2 line 1 |
| 151 | +@@ -6 +6 @@ Common middle line 3 |
| 152 | +-Blob 1 line 2 |
| 153 | ++Blob 2 line 2 |
| 154 | +""" |
| 155 | + |
| 156 | +PATCH_BLOBS_ONE_CONTEXT_LINE = """diff --git a/ b/ |
| 157 | +index 0b5ac93..ddfdbcc 100644 |
| 158 | +--- a/ |
| 159 | ++++ b/ |
| 160 | +@@ -1,3 +1,3 @@ |
| 161 | + Common header of the file |
| 162 | +-Blob 1 line 1 |
| 163 | ++Blob 2 line 1 |
| 164 | + Common middle line 1 |
| 165 | +@@ -5,3 +5,3 @@ Common middle line 2 |
| 166 | + Common middle line 3 |
| 167 | +-Blob 1 line 2 |
| 168 | ++Blob 2 line 2 |
| 169 | + Common footer of the file |
| 170 | +""" |
| 171 | + |
110 | 172 |
|
111 | 173 | def test_diff_empty_index(dirtyrepo):
|
112 | 174 | repo = dirtyrepo
|
@@ -382,3 +444,17 @@ def test_parse_diff_bad():
|
382 | 444 | )
|
383 | 445 | with pytest.raises(pygit2.GitError):
|
384 | 446 | pygit2.Diff.parse_diff(diff)
|
| 447 | + |
| 448 | + |
| 449 | +def test_diff_blobs(emptyrepo): |
| 450 | + repo = emptyrepo |
| 451 | + blob1 = repo.create_blob(TEXT_BLOB1.encode()) |
| 452 | + blob2 = repo.create_blob(TEXT_BLOB2.encode()) |
| 453 | + diff_default = repo.diff(blob1, blob2) |
| 454 | + assert diff_default.text == PATCH_BLOBS_DEFAULT |
| 455 | + diff_no_leeway = repo.diff(blob1, blob2, context_lines=0) |
| 456 | + assert diff_no_leeway.text == PATCH_BLOBS_NO_LEEWAY |
| 457 | + diff_one_context_line = repo.diff(blob1, blob2, context_lines=1) |
| 458 | + assert diff_one_context_line.text == PATCH_BLOBS_ONE_CONTEXT_LINE |
| 459 | + diff_all_together = repo.diff(blob1, blob2, context_lines=1, interhunk_lines=1) |
| 460 | + assert diff_all_together.text == PATCH_BLOBS_DEFAULT |
0 commit comments