On Thu, Aug 1, 2019 at 9:16 AM Varun Naik <vcnaik94@xxxxxxxxx> wrote: > > It is possible to delete a committed file from the index and then add it > as intent-to-add. Certain forms of `git diff` should show the file. > After `git reset HEAD`, the file should be identical in the index and > HEAD. The commands already work correctly if the file has contents in > HEAD. This patch provides the desired behavior even when the file is > empty in HEAD. > > The affected "diff" commands and the "reset" command call > diff-lib.c:do_oneway_diff() with a cache entry in the index and a cache > entry in HEAD. An ita file is represented in the index by a cache entry > with the same hash as an empty file. For a nonempty deleted ita file, > do_oneway_diff() calls show_modified(), which detects a diff between the > cache entry in the index and the cache entry in HEAD and therefore deems > the file "modified". However, for an empty deleted ita file, > do_oneway_diff() previously detected no such diff between the two cache > entries and therefore deemed the file "not modified". After this fix, > for any deleted ita file, do_oneway_diff() calls diff_index_show_file() > and deems the file "deleted". > > `git diff-index --cached HEAD` prints a row of output for both a > "modified" and a "deleted" file, although the output differs slightly. > `git reset HEAD` treats a "modified" and a "deleted" file similarly, > resurrecting the file in the index from HEAD. > > This change should not affect newly added ita files. For those, the > "tree" cache entry is NULL, so the changed code is not executed. > > Helped-by: Junio C Hamano <gitster@xxxxxxxxx> > Signed-off-by: Varun Naik <vcnaik94@xxxxxxxxx> > --- Bumping this email, since I noticed v2 is still in pu. Varun