GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

Command iter_change_type(change_type) returns that some files are modifed when they are renamed

Open SpringEp opened this issue 7 years ago • 2 comments

Command iter_change_type(change_type) returns that file was modified when actually it was renamed. I think that the problem is in this condition elif change_type == "M" and diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob: yield diff which is satisfied for some renamed files when the hashes for a_blob and b_blob change. I know that this shouldn't be the case and that the hashes should be the same in case of file renaming, but I have a several diffs with this problem.

Do you know how can I overcome this problem and have you thought about adding an extra condition that diff.renamed == False?

Link to photo https://imgur.com/a/0DrhOUu

SpringEp avatar Dec 26 '18 16:12 SpringEp

Thanks for having dug into the issue, as I think your work can greatly facilitate a PR. I think this kind of issue could easily be fixed by adding a respective test-case and then adjust the code for this to be fixed. A PR is very welcome.

Byron avatar Jan 01 '19 18:01 Byron

I've looked into the code, and, correct me if I'm mistaken, but I think that the root of the problem regarding the changing hash comes from the __hash__() method in IndexObject, which Blob inherits from. The hash for IndexObject is calculated from path as "index items are uniquely identifiable by path, not by their data". So maybe Blob should override the base class' __hash__() method?

Does that sound right, or am I a bit off base here?

CptMikhailov avatar Feb 13 '19 04:02 CptMikhailov