]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2015-checkout-unborn.sh
Merge branch 'js/range-diff-wo-dotdot'
[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
cc580af8
JK
7. ./test-lib.sh
8
9test_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 ) &&
883b98ef 17 git fetch parent main:origin
cc580af8
JK
18'
19
20test_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
25'
26
27test_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
35'
36
37test_expect_success 'checkout from unborn merges identical index contents' '
38 echo content >file &&
39 git add file &&
40 git checkout -b new origin
41'
42
abe19980
JH
43test_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
50'
51
8338f771
EFL
52test_expect_success 'checking out in a newly created repo' '
53 test_create_repo empty &&
54 (
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
60 )
61'
62
cc580af8 63test_done