Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Nanako Shiraishi | d592b31 | 2008-09-03 17:59:31 +0900 | [diff] [blame] | 3 | test_description='git reset in a bare repository' |
Ævar Arnfjörð Bjarmason | d96fb14 | 2021-10-31 00:24:13 +0200 | [diff] [blame] | 4 | |
| 5 | TEST_PASSES_SANITIZE_LEAK=true |
Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
| 8 | test_expect_success 'setup non-bare' ' |
| 9 | echo one >file && |
| 10 | git add file && |
| 11 | git commit -m one && |
| 12 | echo two >file && |
| 13 | git commit -a -m two |
| 14 | ' |
| 15 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 16 | test_expect_success '"hard" reset requires a worktree' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 17 | (cd .git && |
| 18 | test_must_fail git reset --hard) |
| 19 | ' |
| 20 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 21 | test_expect_success '"merge" reset requires a worktree' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 22 | (cd .git && |
| 23 | test_must_fail git reset --merge) |
| 24 | ' |
| 25 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 26 | test_expect_success '"keep" reset requires a worktree' ' |
| 27 | (cd .git && |
| 28 | test_must_fail git reset --keep) |
| 29 | ' |
| 30 | |
| 31 | test_expect_success '"mixed" reset is ok' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 32 | (cd .git && git reset) |
| 33 | ' |
| 34 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 35 | test_expect_success '"soft" reset is ok' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 36 | (cd .git && git reset --soft) |
| 37 | ' |
| 38 | |
Jeff King | cd0f0f6 | 2009-12-30 03:47:03 -0500 | [diff] [blame] | 39 | test_expect_success 'hard reset works with GIT_WORK_TREE' ' |
| 40 | mkdir worktree && |
| 41 | GIT_WORK_TREE=$PWD/worktree GIT_DIR=$PWD/.git git reset --hard && |
| 42 | test_cmp file worktree/file |
| 43 | ' |
| 44 | |
Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 45 | test_expect_success 'setup bare' ' |
| 46 | git clone --bare . bare.git && |
| 47 | cd bare.git |
| 48 | ' |
| 49 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 50 | test_expect_success '"hard" reset is not allowed in bare' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 51 | test_must_fail git reset --hard HEAD^ |
Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 52 | ' |
| 53 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 54 | test_expect_success '"merge" reset is not allowed in bare' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 55 | test_must_fail git reset --merge HEAD^ |
| 56 | ' |
| 57 | |
Christian Couder | ab892a1 | 2010-01-19 05:26:00 +0100 | [diff] [blame] | 58 | test_expect_success '"keep" reset is not allowed in bare' ' |
| 59 | test_must_fail git reset --keep HEAD^ |
| 60 | ' |
| 61 | |
| 62 | test_expect_success '"mixed" reset is not allowed in bare' ' |
Jeff King | 952dfc6 | 2009-12-04 06:11:58 -0500 | [diff] [blame] | 63 | test_must_fail git reset --mixed HEAD^ |
| 64 | ' |
| 65 | |
Ævar Arnfjörð Bjarmason | e5e3751 | 2022-11-08 19:17:37 +0100 | [diff] [blame] | 66 | test_expect_success '"soft" reset is allowed in bare' ' |
Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 67 | git reset --soft HEAD^ && |
Ævar Arnfjörð Bjarmason | c4d1d52 | 2022-03-07 13:48:52 +0100 | [diff] [blame] | 68 | git show --pretty=format:%s >out && |
| 69 | echo one >expect && |
| 70 | head -n 1 out >actual && |
| 71 | test_cmp expect actual |
Jeff King | 49b9362 | 2007-12-31 02:13:52 -0500 | [diff] [blame] | 72 | ' |
| 73 | |
| 74 | test_done |