]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2015-checkout-unborn.sh
The third batch
[thirdparty/git.git] / t / t2015-checkout-unborn.sh
1 #!/bin/sh
2
3 test_description='checkout from unborn branch'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 mkdir parent &&
12 (
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
20 '
21
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
27 '
28
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
37 '
38
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
43 '
44
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
52 '
53
54 test_expect_success 'checking out in a newly created repo' '
55 test_create_repo empty &&
56 (
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
62 )
63 '
64
65 test_done