Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git reset should work on unborn branch' |
Ævar Arnfjörð Bjarmason | 7615cf9 | 2023-02-07 00:07:40 +0100 | [diff] [blame] | 4 | |
| 5 | TEST_PASSES_SANITIZE_LEAK=true |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
| 8 | test_expect_success 'setup' ' |
| 9 | echo a >a && |
| 10 | echo b >b |
| 11 | ' |
| 12 | |
| 13 | test_expect_success 'reset' ' |
| 14 | git add a b && |
| 15 | git reset && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 16 | |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 17 | git ls-files >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 18 | test_must_be_empty actual |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 19 | ' |
| 20 | |
| 21 | test_expect_success 'reset HEAD' ' |
| 22 | rm .git/index && |
| 23 | git add a b && |
| 24 | test_must_fail git reset HEAD |
| 25 | ' |
| 26 | |
| 27 | test_expect_success 'reset $file' ' |
| 28 | rm .git/index && |
| 29 | git add a b && |
| 30 | git reset a && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 31 | |
| 32 | echo b >expect && |
| 33 | git ls-files >actual && |
| 34 | test_cmp expect actual |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 35 | ' |
| 36 | |
Ghanshyam Thakkar | 7abc186 | 2024-02-13 05:35:30 +0530 | [diff] [blame] | 37 | test_expect_success 'reset -p' ' |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 38 | rm .git/index && |
| 39 | git add a && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 40 | echo y >yes && |
Jeff King | b3e9ce1 | 2013-10-25 02:54:06 -0400 | [diff] [blame] | 41 | git reset -p <yes >output && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 42 | |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 43 | git ls-files >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 44 | test_must_be_empty actual && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 45 | test_grep "Unstage" output |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 46 | ' |
| 47 | |
| 48 | test_expect_success 'reset --soft is a no-op' ' |
| 49 | rm .git/index && |
| 50 | git add a && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 51 | git reset --soft && |
| 52 | |
| 53 | echo a >expect && |
| 54 | git ls-files >actual && |
| 55 | test_cmp expect actual |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 56 | ' |
| 57 | |
| 58 | test_expect_success 'reset --hard' ' |
| 59 | rm .git/index && |
| 60 | git add a && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 61 | test_when_finished "echo a >a" && |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 62 | git reset --hard && |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 63 | |
Jonathan Nieder | 95728f7 | 2013-08-24 13:34:14 -0700 | [diff] [blame] | 64 | git ls-files >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 65 | test_must_be_empty actual && |
Martin von Zweigbergk | 166ec2e | 2013-01-14 21:47:50 -0800 | [diff] [blame] | 66 | test_path_is_missing a |
| 67 | ' |
| 68 | |
| 69 | test_done |