rm: skip sparse paths with missing SKIP_WORKTREE
commitd7c4415e554ac62e49c9616bca5087b4b1310e5a
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 24 Sep 2021 15:39:12 +0000 (24 15:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Sep 2021 17:31:02 +0000 (28 10:31 -0700)
tree7f1163aad22d29a73bae90e149d457d8571d4aee
parentf9786f9b85a6930a711e0ca8ba317c619f02bd8b
rm: skip sparse paths with missing SKIP_WORKTREE

If a path does not match the sparse-checkout cone but is somehow missing
the SKIP_WORKTREE bit, then 'git rm' currently succeeds in removing the
file. One reason a user might be in this situation is a merge conflict
outside of the sparse-checkout cone. Removing such a file might be
problematic for users who are not sure what they are doing.

Add a check to path_in_sparse_checkout() when 'git rm' is checking if a
path should be considered for deletion. Of course, this check is ignored
if the '--sparse' option is specified, allowing users who accept the
risks to continue with the removal.

This also removes a confusing behavior where a user asks for a directory
to be removed, but only the entries that are within the sparse-checkout
definition are removed. Now, 'git rm <dir>' will fail without '--sparse'
and will succeed in removing all contained paths with '--sparse'.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rm.c
t/t3602-rm-sparse-checkout.sh