summaryrefslogtreecommitdiff
path: root/builtin-reset.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-12-04 06:11:58 -0500
committerJunio C Hamano <gitster@pobox.com>2009-12-05 10:28:20 -0800
commit952dfc6944b29582482ff50a85c04879406c06ba (patch)
tree2cb74edc7a2ffe1c79149b649ba0bbd3743ef36a /builtin-reset.c
parent50d9bbba92c9dd5611a1bb592fc42463212413ad (diff)
downloadgit-952dfc6944b29582482ff50a85c04879406c06ba.tar.gz
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>
Diffstat (limited to 'builtin-reset.c')
-rw-r--r--builtin-reset.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin-reset.c b/builtin-reset.c
index 73e60223db..11d1c6e4d6 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -286,8 +286,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (reset_type == NONE)
reset_type = MIXED; /* by default */
- if (reset_type == HARD && is_bare_repository())
- die("hard reset makes no sense in a bare repository");
+ if ((reset_type == HARD || reset_type == MERGE)
+ && !is_inside_work_tree())
+ die("%s reset requires a work tree",
+ reset_type_names[reset_type]);
/* Soft reset does not touch the index file nor the working tree
* at all, but requires them in a good order. Other resets reset