Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Mar 30, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 30, 2021

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.

filepath = self.source_file

Due to that, tools which detect changed files (like lint-diffs) use non-existing files.

@liinus
Copy link

liinus commented Apr 12, 2021

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.

@matiasb
Copy link
Owner

matiasb commented May 7, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants