blob: 88d1c8adf42eec1c219f50b9765d5b3c10d706fa [file] [log] [blame]
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -08001#!/bin/sh
2
3test_description='git reset should work on unborn branch'
Ævar Arnfjörð Bjarmason7615cf92023-02-07 00:07:40 +01004
5TEST_PASSES_SANITIZE_LEAK=true
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -08006. ./test-lib.sh
7
8test_expect_success 'setup' '
9 echo a >a &&
10 echo b >b
11'
12
13test_expect_success 'reset' '
14 git add a b &&
15 git reset &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070016
Jonathan Nieder95728f72013-08-24 13:34:14 -070017 git ls-files >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000018 test_must_be_empty actual
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080019'
20
21test_expect_success 'reset HEAD' '
22 rm .git/index &&
23 git add a b &&
24 test_must_fail git reset HEAD
25'
26
27test_expect_success 'reset $file' '
28 rm .git/index &&
29 git add a b &&
30 git reset a &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070031
32 echo b >expect &&
33 git ls-files >actual &&
34 test_cmp expect actual
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080035'
36
Ghanshyam Thakkar7abc1862024-02-13 05:35:30 +053037test_expect_success 'reset -p' '
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080038 rm .git/index &&
39 git add a &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070040 echo y >yes &&
Jeff Kingb3e9ce12013-10-25 02:54:06 -040041 git reset -p <yes >output &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070042
Jonathan Nieder95728f72013-08-24 13:34:14 -070043 git ls-files >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000044 test_must_be_empty actual &&
Junio C Hamano67892752023-10-31 14:23:30 +090045 test_grep "Unstage" output
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080046'
47
48test_expect_success 'reset --soft is a no-op' '
49 rm .git/index &&
50 git add a &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070051 git reset --soft &&
52
53 echo a >expect &&
54 git ls-files >actual &&
55 test_cmp expect actual
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080056'
57
58test_expect_success 'reset --hard' '
59 rm .git/index &&
60 git add a &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070061 test_when_finished "echo a >a" &&
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080062 git reset --hard &&
Jonathan Nieder95728f72013-08-24 13:34:14 -070063
Jonathan Nieder95728f72013-08-24 13:34:14 -070064 git ls-files >actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000065 test_must_be_empty actual &&
Martin von Zweigbergk166ec2e2013-01-14 21:47:50 -080066 test_path_is_missing a
67'
68
69test_done