object-name: diagnose trees in index properly
commit4925adb4dac1f794cc5d5c82dee49e2f5f47560f
authorDerrick Stolee <derrickstolee@github.com>
Tue, 26 Apr 2022 20:43:19 +0000 (26 20:43 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Apr 2022 20:56:39 +0000 (26 13:56 -0700)
tree47e2e9080b2f754f643f2cb6cf487edd5dd9102d
parent561287d342cc55205b6cac33415ed96a6f112558
object-name: diagnose trees in index properly

When running 'git show :<path>' where '<path>' is a directory, then
there is a subtle difference between a full checkout and a sparse
checkout. The error message from diagnose_invalid_index_path() reports
whether the path is on disk or not. The full checkout will have the
directory on disk, but the path will not be in the index. The sparse
checkout could have the directory not exist, specifically when that
directory is outside of the sparse-checkout cone.

In the case of a sparse index, we have yet another state: the path can
be a sparse directory in the index. In this case, the error message from
diagnose_invalid_index_path() would erroneously say "path '<path>' is in
the index, but not at stage 0", which is false.

Add special casing around sparse directory entries so we get to the
correct error message. This requires two checks in order to get parity
with the normal sparse-checkout case.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-name.c
t/t1092-sparse-checkout-compatibility.sh