| 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-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup' ' |
| 10 | mkdir parent && |
| 11 | ( |
| 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 |
| 19 | ' |
| 20 | |
| 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 |
| 26 | ' |
| 27 | |
| 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 |
| 36 | ' |
| 37 | |
| 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 |
| 42 | ' |
| 43 | |
| 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 |
| 51 | ' |
| 52 | |
| 53 | test_expect_success 'checking out in a newly created repo' ' |
| 54 | test_create_repo empty && |
| 55 | ( |
| 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 |
| 61 | ) |
| 62 | ' |
| 63 | |
| 64 | test_done |