MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_diff_unchanged_file_no_patch

Function test_diff_unchanged_file_no_patch

test/test_diff.py:479–506  ·  view source on GitHub ↗
(testrepo: Repository)

Source from the content-addressed store, hash-verified

477
478
479def 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'

Callers

nothing calls this directly

Calls 1

diffMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…