Sync with 2.38.5
[git.git] / t / t2015-checkout-unborn.sh
blob9425aae6395838b3d0fd57b8cf8fe228d1db335f
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 &&
12 (cd parent &&
13 git init &&
14 echo content >file &&
15 git add file &&
16 git commit -m base
17 ) &&
18 git fetch parent main:origin
21 test_expect_success 'checkout from unborn preserves untracked files' '
22 echo precious >expect &&
23 echo precious >file &&
24 test_must_fail git checkout -b new origin &&
25 test_cmp expect file
28 test_expect_success 'checkout from unborn preserves index contents' '
29 echo precious >expect &&
30 echo precious >file &&
31 git add file &&
32 test_must_fail git checkout -b new origin &&
33 test_cmp expect file &&
34 git show :file >file &&
35 test_cmp expect file
38 test_expect_success 'checkout from unborn merges identical index contents' '
39 echo content >file &&
40 git add file &&
41 git checkout -b new origin
44 test_expect_success 'checking out another branch from unborn state' '
45 git checkout --orphan newroot &&
46 git checkout -b anothername &&
47 test_must_fail git show-ref --verify refs/heads/newroot &&
48 git symbolic-ref HEAD >actual &&
49 echo refs/heads/anothername >expect &&
50 test_cmp expect actual
53 test_expect_success 'checking out in a newly created repo' '
54 test_create_repo empty &&
56 cd empty &&
57 git symbolic-ref HEAD >expect &&
58 test_must_fail git checkout &&
59 git symbolic-ref HEAD >actual &&
60 test_cmp expect actual
64 test_done