@matheusbsbs / matheus-bagliano / commits / 49b9362fd3
Fork 0

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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 31, 2007 at 02:13 UTC 49b9362fd35d45dc94ea15006c4bb88671b8da7d
2 files changed +31
builtin-reset.c
+3
@@ -244,6 +244,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
244 if (reset_type == NONE)
245 reset_type = MIXED; /* by default */
246
247 + if (reset_type == HARD && is_bare_repository())
248 + die("hard reset makes no sense in a bare repository");
249 +
250 /* Soft reset does not touch the index file nor the working tree
251 * at all, but requires them in a good order. Other resets reset
252 * the index file to the tree object we are switching to. */
t/t7103-reset-bare.sh new
+28
@@ -0,0 +1,28 @@
1 +#!/bin/sh
2 +
3 +test_description='git-reset in a bare repository'
4 +. ./test-lib.sh
5 +
6 +test_expect_success 'setup non-bare' '
7 + echo one >file &&
8 + git add file &&
9 + git commit -m one &&
10 + echo two >file &&
11 + git commit -a -m two
12 +'
13 +
14 +test_expect_success 'setup bare' '
15 + git clone --bare . bare.git &&
16 + cd bare.git
17 +'
18 +
19 +test_expect_success 'hard reset is not allowed' '
20 + ! git reset --hard HEAD^
21 +'
22 +
23 +test_expect_success 'soft reset is allowed' '
24 + git reset --soft HEAD^ &&
25 + test "`git show --pretty=format:%s | head -n 1`" = "one"
26 +'
27 +
28 +test_done