python-unidiff icon indicating copy to clipboard operation
python-unidiff copied to clipboard

File renames aren't handled properly because PatchSet.path returns a source filename

Open ghost opened this issue 3 years ago • 2 comments

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.

ghost avatar Mar 30 '21 06:03 ghost

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.

liinus avatar Apr 12 '21 17:04 liinus

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.

matiasb avatar May 07 '21 12:05 matiasb