@matheusbsbs / matheus-bagliano / commits / ab892a19e8
Fork 0

reset: disallow "reset --keep" outside a work tree

It is safer and consistent with "--merge" and "--hard" resets to disallow "git reset --keep" outside a work tree. So let's just do that and add some tests while at it. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jan 19, 2010 at 05:26 UTC ab892a19e83edd1cf9a767bc09d3239f72469d05
2 files changed +18 -9
builtin-reset.c
+1 -1
@@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
319 if (reset_type == NONE)
320 reset_type = MIXED; /* by default */
321
322 - if (reset_type == HARD || reset_type == MERGE)
322 + if (reset_type != SOFT && reset_type != MIXED)
323 setup_work_tree();
324
325 if (reset_type == MIXED && is_bare_repository())
t/t7103-reset-bare.sh
+17 -8
@@ -11,21 +11,26 @@ test_expect_success 'setup non-bare' '
11 git commit -a -m two
12 '
13
14 -test_expect_success 'hard reset requires a worktree' '
14 +test_expect_success '"hard" reset requires a worktree' '
15 (cd .git &&
16 test_must_fail git reset --hard)
17 '
18
19 -test_expect_success 'merge reset requires a worktree' '
19 +test_expect_success '"merge" reset requires a worktree' '
20 (cd .git &&
21 test_must_fail git reset --merge)
22 '
23
24 -test_expect_success 'mixed reset is ok' '
24 +test_expect_success '"keep" reset requires a worktree' '
25 + (cd .git &&
26 + test_must_fail git reset --keep)
27 +'
28 +
29 +test_expect_success '"mixed" reset is ok' '
30 (cd .git && git reset)
31 '
32
28 -test_expect_success 'soft reset is ok' '
33 +test_expect_success '"soft" reset is ok' '
34 (cd .git && git reset --soft)
35 '
36
@@ -40,19 +45,23 @@ test_expect_success 'setup bare' '
45 cd bare.git
46 '
47
43 -test_expect_success 'hard reset is not allowed in bare' '
48 +test_expect_success '"hard" reset is not allowed in bare' '
49 test_must_fail git reset --hard HEAD^
50 '
51
47 -test_expect_success 'merge reset is not allowed in bare' '
52 +test_expect_success '"merge" reset is not allowed in bare' '
53 test_must_fail git reset --merge HEAD^
54 '
55
51 -test_expect_success 'mixed reset is not allowed in bare' '
56 +test_expect_success '"keep" reset is not allowed in bare' '
57 + test_must_fail git reset --keep HEAD^
58 +'
59 +
60 +test_expect_success '"mixed" reset is not allowed in bare' '
61 test_must_fail git reset --mixed HEAD^
62 '
63
55 -test_expect_success 'soft reset is allowed in bare' '
64 +test_expect_success '"soft" reset is allowed in bare' '
65 git reset --soft HEAD^ &&
66 test "`git show --pretty=format:%s | head -n 1`" = "one"
67 '