提交 49b9362f 编写于 作者: J Jeff King 提交者: Junio C Hamano

git-reset: refuse to do hard reset in a bare repository

It makes no sense since there is no working tree. A soft
reset should be fine, though.
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 02e5ba4a
......@@ -244,6 +244,9 @@ 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");
/* Soft reset does not touch the index file nor the working tree
* at all, but requires them in a good order. Other resets reset
* the index file to the tree object we are switching to. */
......
#!/bin/sh
test_description='git-reset in a bare repository'
. ./test-lib.sh
test_expect_success 'setup non-bare' '
echo one >file &&
git add file &&
git commit -m one &&
echo two >file &&
git commit -a -m two
'
test_expect_success 'setup bare' '
git clone --bare . bare.git &&
cd bare.git
'
test_expect_success 'hard reset is not allowed' '
! git reset --hard HEAD^
'
test_expect_success 'soft reset is allowed' '
git reset --soft HEAD^ &&
test "`git show --pretty=format:%s | head -n 1`" = "one"
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册