(testrepo: Repository)
| 477 | |
| 478 | |
| 479 | def test_diff_unchanged_file_no_patch(testrepo: Repository) -> None: |
| 480 | repo = testrepo |
| 481 | |
| 482 | # Convert hello.txt line endings to CRLF |
| 483 | path = Path(repo.workdir) / 'hello.txt' |
| 484 | data = path.read_bytes() |
| 485 | data = data.replace(b'\n', b'\r\n') |
| 486 | path.write_bytes(data) |
| 487 | |
| 488 | # Enable CRLF filter |
| 489 | repo.config['core.autocrlf'] = 'input' |
| 490 | |
| 491 | diff = repo.diff() |
| 492 | assert len(diff) == 1 |
| 493 | |
| 494 | # Get patch #0 in the same diff several times. |
| 495 | # git_patch_from_diff eventually decides that the file is "unchanged"; |
| 496 | # it returns a NULL patch in this case. |
| 497 | # https://libgit2.org/docs/reference/main/patch/git_patch_from_diff |
| 498 | for i in range(10): # loop typically exits in the third iteration |
| 499 | patch = diff[0] |
| 500 | if patch is None: # libgit2 decides the file is unchanged |
| 501 | break |
| 502 | assert patch.delta.new_file.path == path.name |
| 503 | assert patch.text == '' # no content change (just line endings) |
| 504 | else: |
| 505 | # Didn't find the edge case that this test is supposed to exercise. |
| 506 | assert False, 'libgit2 rebuilt a new patch every time' |
nothing calls this directly
no test coverage detected
searching dependent graphs…