diff options
-rw-r--r-- | builtin-reset.c | 6 | ||||
-rwxr-xr-x | t/t7103-reset-bare.sh | 32 |
2 files changed, 33 insertions, 5 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 diff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh index 42bf518c68..68041df5f4 100755 --- a/t/t7103-reset-bare.sh +++ b/t/t7103-reset-bare.sh @@ -11,16 +11,42 @@ test_expect_success 'setup non-bare' ' git commit -a -m two ' +test_expect_success 'hard reset requires a worktree' ' + (cd .git && + test_must_fail git reset --hard) +' + +test_expect_success 'merge reset requires a worktree' ' + (cd .git && + test_must_fail git reset --merge) +' + +test_expect_success 'mixed reset is ok' ' + (cd .git && git reset) +' + +test_expect_success 'soft reset is ok' ' + (cd .git && git reset --soft) +' + test_expect_success 'setup bare' ' git clone --bare . bare.git && cd bare.git ' -test_expect_success 'hard reset is not allowed' ' - test_must_fail git reset --hard HEAD^ +test_expect_success 'hard reset is not allowed in bare' ' + test_must_fail git reset --hard HEAD^ +' + +test_expect_success 'merge reset is not allowed in bare' ' + test_must_fail git reset --merge HEAD^ +' + +test_expect_success 'mixed reset is not allowed in bare' ' + test_must_fail git reset --mixed HEAD^ ' -test_expect_success 'soft reset is allowed' ' +test_expect_success 'soft reset is allowed in bare' ' git reset --soft HEAD^ && test "`git show --pretty=format:%s | head -n 1`" = "one" ' |