The twelfth batch
[git/gitster.git] / t / t2015-checkout-unborn.sh
blobfb0e13881cd8a290dd272c6dc16c3f097f49cb39
1 #!/bin/sh
3 test_description='checkout from unborn branch'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 mkdir parent &&
13 cd parent &&
14 git init &&
15 echo content >file &&
16 git add file &&
17 git commit -m base
18 ) &&
19 git fetch parent main:origin
22 test_expect_success 'checkout from unborn preserves untracked files' '
23 echo precious >expect &&
24 echo precious >file &&
25 test_must_fail git checkout -b new origin &&
26 test_cmp expect file
29 test_expect_success 'checkout from unborn preserves index contents' '
30 echo precious >expect &&
31 echo precious >file &&
32 git add file &&
33 test_must_fail git checkout -b new origin &&
34 test_cmp expect file &&
35 git show :file >file &&
36 test_cmp expect file
39 test_expect_success 'checkout from unborn merges identical index contents' '
40 echo content >file &&
41 git add file &&
42 git checkout -b new origin
45 test_expect_success 'checking out another branch from unborn state' '
46 git checkout --orphan newroot &&
47 git checkout -b anothername &&
48 test_must_fail git show-ref --verify refs/heads/newroot &&
49 git symbolic-ref HEAD >actual &&
50 echo refs/heads/anothername >expect &&
51 test_cmp expect actual
54 test_expect_success 'checking out in a newly created repo' '
55 test_create_repo empty &&
57 cd empty &&
58 git symbolic-ref HEAD >expect &&
59 test_must_fail git checkout &&
60 git symbolic-ref HEAD >actual &&
61 test_cmp expect actual
65 test_done