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

Fixes #962: First create a git_patch to get delta->flags correctly #1100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@ PyTypeObject DiffIterType = {
PyObject *
diff_get_delta_byindex(git_diff *diff, size_t idx)
{
git_patch *patch = NULL;
int err;

/* create a git_patch in order to store delta->flags */
err = git_patch_from_diff(&patch, diff, idx);
if (err < 0) {
PyErr_SetObject(PyExc_IndexError, PyLong_FromSize_t(idx));
return NULL;
}
git_patch_free(patch);

const git_diff_delta *delta = git_diff_get_delta(diff, idx);
if (delta == NULL) {
PyErr_SetObject(PyExc_IndexError, PyLong_FromSize_t(idx));
Expand Down
4 changes: 1 addition & 3 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ def test_deltas(barerepo):
assert delta.nfiles == patch_delta.nfiles
assert delta.old_file.id == patch_delta.old_file.id
assert delta.new_file.id == patch_delta.new_file.id

# As explained in the libgit2 documentation, flags are not set
#assert delta.flags == patch_delta.flags
assert delta.flags == patch_delta.flags

def test_diff_parse(barerepo):
diff = pygit2.Diff.parse_diff(PATCH)
Expand Down