blob: 18bbd9975ebfda330d0727c600bd0cec4b8b5181 [file] [log] [blame]
Jeff King49b93622007-12-31 02:13:52 -05001#!/bin/sh
2
Nanako Shiraishid592b312008-09-03 17:59:31 +09003test_description='git reset in a bare repository'
Ævar Arnfjörð Bjarmasond96fb142021-10-31 00:24:13 +02004
5TEST_PASSES_SANITIZE_LEAK=true
Jeff King49b93622007-12-31 02:13:52 -05006. ./test-lib.sh
7
8test_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 Couderab892a12010-01-19 05:26:00 +010016test_expect_success '"hard" reset requires a worktree' '
Jeff King952dfc62009-12-04 06:11:58 -050017 (cd .git &&
18 test_must_fail git reset --hard)
19'
20
Christian Couderab892a12010-01-19 05:26:00 +010021test_expect_success '"merge" reset requires a worktree' '
Jeff King952dfc62009-12-04 06:11:58 -050022 (cd .git &&
23 test_must_fail git reset --merge)
24'
25
Christian Couderab892a12010-01-19 05:26:00 +010026test_expect_success '"keep" reset requires a worktree' '
27 (cd .git &&
28 test_must_fail git reset --keep)
29'
30
31test_expect_success '"mixed" reset is ok' '
Jeff King952dfc62009-12-04 06:11:58 -050032 (cd .git && git reset)
33'
34
Christian Couderab892a12010-01-19 05:26:00 +010035test_expect_success '"soft" reset is ok' '
Jeff King952dfc62009-12-04 06:11:58 -050036 (cd .git && git reset --soft)
37'
38
Jeff Kingcd0f0f62009-12-30 03:47:03 -050039test_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 King49b93622007-12-31 02:13:52 -050045test_expect_success 'setup bare' '
46 git clone --bare . bare.git &&
47 cd bare.git
48'
49
Christian Couderab892a12010-01-19 05:26:00 +010050test_expect_success '"hard" reset is not allowed in bare' '
Jeff King952dfc62009-12-04 06:11:58 -050051 test_must_fail git reset --hard HEAD^
Jeff King49b93622007-12-31 02:13:52 -050052'
53
Christian Couderab892a12010-01-19 05:26:00 +010054test_expect_success '"merge" reset is not allowed in bare' '
Jeff King952dfc62009-12-04 06:11:58 -050055 test_must_fail git reset --merge HEAD^
56'
57
Christian Couderab892a12010-01-19 05:26:00 +010058test_expect_success '"keep" reset is not allowed in bare' '
59 test_must_fail git reset --keep HEAD^
60'
61
62test_expect_success '"mixed" reset is not allowed in bare' '
Jeff King952dfc62009-12-04 06:11:58 -050063 test_must_fail git reset --mixed HEAD^
64'
65
Ævar Arnfjörð Bjarmasone5e37512022-11-08 19:17:37 +010066test_expect_success '"soft" reset is allowed in bare' '
Jeff King49b93622007-12-31 02:13:52 -050067 git reset --soft HEAD^ &&
Ævar Arnfjörð Bjarmasonc4d1d522022-03-07 13:48:52 +010068 git show --pretty=format:%s >out &&
69 echo one >expect &&
70 head -n 1 out >actual &&
71 test_cmp expect actual
Jeff King49b93622007-12-31 02:13:52 -050072'
73
74test_done