]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2015-checkout-unborn.sh
The third batch
[thirdparty/git.git] / t / t2015-checkout-unborn.sh
CommitLineData
cc580af8
JK
1#!/bin/sh
2
abe19980 3test_description='checkout from unborn branch'
883b98ef 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
e75d2f7f 7TEST_PASSES_SANITIZE_LEAK=true
cc580af8
JK
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 mkdir parent &&
d35d8f2e
AP
12 (
13 cd parent &&
14 git init &&
15 echo content >file &&
16 git add file &&
17 git commit -m base
cc580af8 18 ) &&
883b98ef 19 git fetch parent main:origin
cc580af8
JK
20'
21
22test_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
29test_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
39test_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
abe19980
JH
45test_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
8338f771
EFL
54test_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
cc580af8 65test_done