Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t2017-checkout-orphan.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t2017-checkout-orphan.sh` 137 lines ยท 4136 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2010 Erick Mattos 4 # 5 6 test_description='git checkout --orphan 7 8 Main Tests for --orphan functionality.' 9 10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 12 13 . ./test-lib.sh 14 15 TEST_FILE=foo 16 17 test_expect_success 'Setup' ' 18 echo "Initial" >"$TEST_FILE" && 19 git add "$TEST_FILE" && 20 git commit -m "First Commit" && 21 test_tick && 22 echo "State 1" >>"$TEST_FILE" && 23 git add "$TEST_FILE" && 24 test_tick && 25 git commit -m "Second Commit" 26 ' 27 28 test_expect_success '--orphan creates a new orphan branch from HEAD' ' 29 git checkout --orphan alpha && 30 test_must_fail git rev-parse --verify HEAD && 31 test "refs/heads/alpha" = "$(git symbolic-ref HEAD)" && 32 test_tick && 33 git commit -m "Third Commit" && 34 test_must_fail git rev-parse --verify HEAD^ && 35 git diff-tree --quiet main alpha 36 ' 37 38 test_expect_success '--orphan creates a new orphan branch from ' ' 39 git checkout main && 40 git checkout --orphan beta main^ && 41 test_must_fail git rev-parse --verify HEAD && 42 test "refs/heads/beta" = "$(git symbolic-ref HEAD)" && 43 test_tick && 44 git commit -m "Fourth Commit" && 45 test_must_fail git rev-parse --verify HEAD^ && 46 git diff-tree --quiet main^ beta 47 ' 48 49 test_expect_success '--orphan must be rejected with -b' ' 50 git checkout main && 51 test_must_fail git checkout --orphan new -b newer && 52 test refs/heads/main = "$(git symbolic-ref HEAD)" 53 ' 54 55 test_expect_success '--orphan must be rejected with -t' ' 56 git checkout main && 57 test_must_fail git checkout --orphan new -t main && 58 test refs/heads/main = "$(git symbolic-ref HEAD)" 59 ' 60 61 test_expect_success '--orphan ignores branch.autosetupmerge' ' 62 git checkout main && 63 git config branch.autosetupmerge always && 64 git checkout --orphan gamma && 65 test_cmp_config "" --default "" branch.gamma.merge && 66 test refs/heads/gamma = "$(git symbolic-ref HEAD)" && 67 test_must_fail git rev-parse --verify HEAD^ && 68 git checkout main && 69 git config branch.autosetupmerge inherit && 70 git checkout --orphan eta && 71 test_cmp_config "" --default "" branch.eta.merge && 72 test_cmp_config "" --default "" branch.eta.remote && 73 echo refs/heads/eta >expected && 74 git symbolic-ref HEAD >actual && 75 test_cmp expected actual && 76 test_must_fail git rev-parse --verify HEAD^ 77 ' 78 79 test_expect_success '--orphan makes reflog by default' ' 80 git checkout main && 81 git config --unset core.logAllRefUpdates && 82 git checkout --orphan delta && 83 test_must_fail git rev-parse --verify delta@{0} && 84 git commit -m Delta && 85 git rev-parse --verify delta@{0} 86 ' 87 88 test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' ' 89 git checkout main && 90 git config core.logAllRefUpdates false && 91 git checkout --orphan epsilon && 92 test_must_fail git rev-parse --verify epsilon@{0} && 93 git commit -m Epsilon && 94 test_must_fail git rev-parse --verify epsilon@{0} 95 ' 96 97 test_expect_success '--orphan with -l makes reflog when core.logAllRefUpdates = false' ' 98 git checkout main && 99 git checkout -l --orphan zeta && 100 test_must_fail git rev-parse --verify zeta@{0} && 101 git commit -m Zeta && 102 git rev-parse --verify zeta@{0} 103 ' 104 105 test_expect_success 'giving up --orphan not committed when -l and core.logAllRefUpdates = false deletes reflog' ' 106 git checkout main && 107 git checkout -l --orphan eta && 108 test_must_fail git rev-parse --verify eta@{0} && 109 git checkout main && 110 test_must_fail git rev-parse --verify eta@{0} 111 ' 112 113 test_expect_success '--orphan is rejected with an existing name' ' 114 git checkout main && 115 test_must_fail git checkout --orphan main && 116 test refs/heads/main = "$(git symbolic-ref HEAD)" 117 ' 118 119 test_expect_success '--orphan refuses to switch if a merge is needed' ' 120 git checkout main && 121 git reset --hard && 122 echo local >>"$TEST_FILE" && 123 cat "$TEST_FILE" >"$TEST_FILE.saved" && 124 test_must_fail git checkout --orphan new main^ && 125 test refs/heads/main = "$(git symbolic-ref HEAD)" && 126 test_cmp "$TEST_FILE" "$TEST_FILE.saved" && 127 git diff-index --quiet --cached HEAD && 128 git reset --hard 129 ' 130 131 test_expect_success 'cannot --detach on an unborn branch' ' 132 git checkout main && 133 git checkout --orphan new && 134 test_must_fail git checkout --detach 135 ' 136 137 test_done