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.

Share Improve this question asked Mar 25 at 6:44 eftshift0eftshift0 30.5k5 gold badges52 silver badges77 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

As 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