libgit2 / libgit2

A cross-platform, linkable library implementation of Git that you can use in your application.
https://libgit2.org/
Other
9.69k stars 2.41k forks source link

git_diff_index_to_index does not show added gitlink #3777

Closed joshtriplett closed 8 years ago

joshtriplett commented 8 years ago

I have two indexes, identical except that the second index has a new gitlink (mode 0160000) that the first does not. Calling git_diff_index_to_index produces no deltas, ignoring the gitlink entirely.

In case it matters, there's no .gitmodules file anywhere; these are intentionally "bare" gitlinks. The diff should still show a change, from not having a gitlink to having one. (And if both indexes had a gitlink, but with a different commit hash, that should show up as a delta as well.)

joshtriplett commented 8 years ago

Note that git_diff_tree_to_index seems to handle this situation slightly better in one case: if a gitlink has changed between the tree and the index, it shows up as a delta of type "modified". However, git_diff_tree_to_index still doesn't handle the case of a gitlink that doesn't exist in the tree but exists in the index; that should show up as a delta of type "added", but it doesn't show up at all.

joshtriplett commented 8 years ago

Here's a test case. Extract testrepo.tar.gz, which includes both a test repository and the test program. From within the testrepo directory, first run git ls-files -s, which should show a gitlink named series and a blob named test:

160000 1cbd3d53a0e72d00b2b06eee7cce5d90029df451 0   series
100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 0   test

Compile git-test.c with gcc $(pkg-config --cflags --libs libgit2) git-test.c -o git-test. Run it with ./git-test. It will show only one delta, for the blob test, but no delta for the gitlink series.

joshtriplett commented 8 years ago

After some careful debugging, I managed to track down the issue, which turned out to be in the code that constructed the index; the submodule entries had been created with GIT_IDXENTRY_VALID (the "assume unchanged" bit) set.

It would help to have a bit more documentation on GIT_IDXENTRY_VALID (to make it clear that it means "assume unchanged"), but otherwise this issue can be closed.

ethomson commented 8 years ago

Thanks for digging in to this - and for reporting back. Indeed this makes sense:

It would help to have a bit more documentation on GIT_IDXENTRY_VALID (to make it clear that it means "assume unchanged")

I definitely agree with this. Thanks for reminding me that this is a problem. I opened #3778 to track it since I regrettably cannot get to it today.