admin管理员组文章数量:1401122
I am running a diff between 2 consecutive commits and the only change between them is a rename of one file without any change in content involved. If I run a show on the parent commit, I get this from git:
$ git show --pretty="" the_parent_commit
diff --git a/a-script.py b/a-script
similarity index 100%
rename from a-script.py
rename to a-script
To be even more certain that there are no changes involved, I looked at the object IDs of the files:
$ git rev-parse the_parent_commit~:a-script.py the_parent_commit:a-script
I get twice the same object ID.
Now.... I would expect pygit2.Repository.diff
to report this rename... instead it's saying that the file was ADDED
and a single hunk in the patch is showing all lines to have been added in the file. I am not passing down any options to it (I checked the DiffOption
enum to see if one of those would be needed so that the rename was detected but I do not see anyone that sounds related).
Do you have a tip how to get pygit2
to get this to work correctly? My guess is that the question is more related to libgit2
so I am adding the tag.
I am running a diff between 2 consecutive commits and the only change between them is a rename of one file without any change in content involved. If I run a show on the parent commit, I get this from git:
$ git show --pretty="" the_parent_commit
diff --git a/a-script.py b/a-script
similarity index 100%
rename from a-script.py
rename to a-script
To be even more certain that there are no changes involved, I looked at the object IDs of the files:
$ git rev-parse the_parent_commit~:a-script.py the_parent_commit:a-script
I get twice the same object ID.
Now.... I would expect pygit2.Repository.diff
to report this rename... instead it's saying that the file was ADDED
and a single hunk in the patch is showing all lines to have been added in the file. I am not passing down any options to it (I checked the DiffOption
enum to see if one of those would be needed so that the rename was detected but I do not see anyone that sounds related).
Do you have a tip how to get pygit2
to get this to work correctly? My guess is that the question is more related to libgit2
so I am adding the tag.
1 Answer
Reset to default 0As it happens, the answer was in pygit2's source code:
class DeltaStatus(IntEnum):
"""
What type of change is described by a DiffDelta?
`RENAMED` and `COPIED` will only show up if you run
`find_similar()` on the Diff object.
https://github/libgit2/pygit2/tree/master/pygit2#L302
本文标签: diffHow can I tell a file was renamed using pygit2Stack Overflow
版权声明:本文标题:diff - How can I tell a file was renamed using pygit2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744214253a2595561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论