python-unidiff
python-unidiff copied to clipboard
File renames aren't handled properly because PatchSet.path returns a source filename
File renames aren't handled properly because PatchedFile.path returns a source filename which doesn't exist after the operation. Probably it should return a target filename.
https://github.com/matiasb/python-unidiff/blob/9a473c8ca2cc71614b6e1470019d30065941cafe/unidiff/patch.py#L369
Due to that, tools which detect changed files (like lint-diffs) use non-existing files.
from unidiff import PatchSet
diff_str = """Submodule sub bc856b3..d7ac133:
diff --git a/sub/file.txt b/sub/renamed.txt
similarity index 100%
rename from file.txt
rename to renamed.txt"""
patch = PatchSet.from_string(diff_str)[0]
print(patch.source_file)
print(patch.target_file)
Returns:
a/file.txt
b/renamed.txt
I would expect "sub/" to be part of the source and target file.
I see, returning target file for renamed files makes sense.
OTOH, thanks for the additional report and the example, you are right, it should include the sub/
in the path.
Will take a look.