Skip to content

diff: check the path when looking up the delta for an item - #7394

Open
yerseg wants to merge 1 commit into
libgit2:mainfrom
yerseg:fix-diff-typechange-last-delta
Open

yerseg wants to merge 1 commit into
libgit2:mainfrom
yerseg:fix-diff-typechange-last-delta

Conversation

@yerseg

@yerseg yerseg commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #7392.

diff_delta__last_for_item returned the last delta if the id matched, without checking that the delta was for the same path. When no delta had been created for the item (filtered out by the pathspec or skipped by the notify callback), it could pick up the previous item's delta and turn it into a typechange.

This makes it compare the path as well. The new test fails without the fix.

With GIT_DIFF_INCLUDE_TYPECHANGE_TREES, the diff creates a delta for an
unmatched item and then takes the last delta to turn it into a
typechange.  When no delta is created for the item (because of the
pathspec or the notify callback), the last delta belongs to another
item.  If that item has the same id, its delta becomes a typechange to
a tree: a deleted file `a` is reported as a typechange when a file `c`
with the same contents becomes the directory `c/` and the pathspec
excludes `c`.

Check the path of the last delta as well as the id.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted file shows up as a typechange with GIT_DIFF_INCLUDE_TYPECHANGE_TREES and a pathspec

1 participant