Merge branch 'ab/make-sparse-for-real'
[git/debian.git] / t / t2015-checkout-unborn.sh
bloba9721215fab540ccf6ce1e12f2c5066b620cac6b
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-lib.sh
9 test_expect_success 'setup' '
10 mkdir parent &&
11 (cd parent &&
12 git init &&
13 echo content >file &&
14 git add file &&
15 git commit -m base
16 ) &&
17 git fetch parent main:origin
20 test_expect_success 'checkout from unborn preserves untracked files' '
21 echo precious >expect &&
22 echo precious >file &&
23 test_must_fail git checkout -b new origin &&
24 test_cmp expect file
27 test_expect_success 'checkout from unborn preserves index contents' '
28 echo precious >expect &&
29 echo precious >file &&
30 git add file &&
31 test_must_fail git checkout -b new origin &&
32 test_cmp expect file &&
33 git show :file >file &&
34 test_cmp expect file
37 test_expect_success 'checkout from unborn merges identical index contents' '
38 echo content >file &&
39 git add file &&
40 git checkout -b new origin
43 test_expect_success 'checking out another branch from unborn state' '
44 git checkout --orphan newroot &&
45 git checkout -b anothername &&
46 test_must_fail git show-ref --verify refs/heads/newroot &&
47 git symbolic-ref HEAD >actual &&
48 echo refs/heads/anothername >expect &&
49 test_cmp expect actual
52 test_expect_success 'checking out in a newly created repo' '
53 test_create_repo empty &&
55 cd empty &&
56 git symbolic-ref HEAD >expect &&
57 test_must_fail git checkout &&
58 git symbolic-ref HEAD >actual &&
59 test_cmp expect actual
63 test_done