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