reset: improve worktree safety valves
commit952dfc6944b29582482ff50a85c04879406c06ba
authorJeff King <peff@peff.net>
Fri, 4 Dec 2009 11:11:58 +0000 (4 06:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 5 Dec 2009 18:28:20 +0000 (5 10:28 -0800)
tree2cb74edc7a2ffe1c79149b649ba0bbd3743ef36a
parent50d9bbba92c9dd5611a1bb592fc42463212413ad
reset: improve worktree safety valves

The existing code checked to make sure we were not in a bare
repository when doing a hard reset. However, we should take
this one step further, and make sure we are in a worktree.
Otherwise, we can end up munging files inside of '.git'.

Furthermore, we should do the same check for --merge resets,
which have the same properties. Actually, a merge reset of
HEAD^ would already complain, since further down in the code
we want a worktree. However, it is nicer to check up-front;
then we are sure we cover all cases ("git reset --merge"
would run, even though it wasn't doing anything) and we can
give a more specific message.

Add tests to t7103 to cover these cases and some missing ones.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-reset.c
t/t7103-reset-bare.sh