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/t2012-checkout-last.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 / t2012-checkout-last.sh` 169 lines ยท 3667 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='checkout can switch to last branch and merge base' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 test_expect_success 'setup' ' 11 test_commit initial world hello && 12 git branch other && 13 test_commit --append second world "hello again" 14 ' 15 16 test_expect_success '"checkout -" does not work initially' ' 17 test_must_fail git checkout - 18 ' 19 20 test_expect_success 'first branch switch' ' 21 git checkout other 22 ' 23 24 test_cmp_symbolic_HEAD_ref () { 25 echo refs/heads/"$1" >expect && 26 git symbolic-ref HEAD >actual && 27 test_cmp expect actual 28 } 29 30 test_expect_success '"checkout -" switches back' ' 31 git checkout - && 32 test_cmp_symbolic_HEAD_ref main 33 ' 34 35 test_expect_success '"checkout -" switches forth' ' 36 git checkout - && 37 test_cmp_symbolic_HEAD_ref other 38 ' 39 40 test_expect_success 'detach HEAD' ' 41 git checkout $(git rev-parse HEAD) 42 ' 43 44 test_expect_success '"checkout -" attaches again' ' 45 git checkout - && 46 test_cmp_symbolic_HEAD_ref other 47 ' 48 49 test_expect_success '"checkout -" detaches again' ' 50 git checkout - && 51 52 git rev-parse other >expect && 53 git rev-parse HEAD >actual && 54 test_cmp expect actual && 55 56 test_must_fail git symbolic-ref HEAD 57 ' 58 59 test_expect_success 'more switches' ' 60 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 61 do 62 git checkout -b branch$i || return 1 63 done 64 ' 65 66 more_switches () { 67 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 68 do 69 git checkout branch$i || return 1 70 done 71 } 72 73 test_expect_success 'switch to the last' ' 74 more_switches && 75 git checkout @{-1} && 76 test_cmp_symbolic_HEAD_ref branch2 77 ' 78 79 test_expect_success 'switch to second from the last' ' 80 more_switches && 81 git checkout @{-2} && 82 test_cmp_symbolic_HEAD_ref branch3 83 ' 84 85 test_expect_success 'switch to third from the last' ' 86 more_switches && 87 git checkout @{-3} && 88 test_cmp_symbolic_HEAD_ref branch4 89 ' 90 91 test_expect_success 'switch to fourth from the last' ' 92 more_switches && 93 git checkout @{-4} && 94 test_cmp_symbolic_HEAD_ref branch5 95 ' 96 97 test_expect_success 'switch to twelfth from the last' ' 98 more_switches && 99 git checkout @{-12} && 100 test_cmp_symbolic_HEAD_ref branch13 101 ' 102 103 test_expect_success 'merge base test setup' ' 104 git checkout -b another other && 105 test_commit --append third world "hello again" 106 ' 107 108 test_expect_success 'another...main' ' 109 git checkout another && 110 git checkout another...main && 111 112 git rev-parse --verify main^ >expect && 113 git rev-parse --verify HEAD >actual && 114 test_cmp expect actual 115 ' 116 117 test_expect_success '...main' ' 118 git checkout another && 119 git checkout ...main && 120 121 git rev-parse --verify main^ >expect && 122 git rev-parse --verify HEAD >actual && 123 test_cmp expect actual 124 ' 125 126 test_expect_success 'main...' ' 127 git checkout another && 128 git checkout main... && 129 130 git rev-parse --verify main^ >expect && 131 git rev-parse --verify HEAD >actual && 132 test_cmp expect actual 133 ' 134 135 test_expect_success '"checkout -" works after a rebase A' ' 136 git checkout main && 137 git checkout other && 138 git rebase main && 139 git checkout - && 140 test_cmp_symbolic_HEAD_ref main 141 ' 142 143 test_expect_success '"checkout -" works after a rebase A B' ' 144 git branch moodle main~1 && 145 git checkout main && 146 git checkout other && 147 git rebase main moodle && 148 git checkout - && 149 test_cmp_symbolic_HEAD_ref main 150 ' 151 152 test_expect_success '"checkout -" works after a rebase -i A' ' 153 git checkout main && 154 git checkout other && 155 git rebase -i main && 156 git checkout - && 157 test_cmp_symbolic_HEAD_ref main 158 ' 159 160 test_expect_success '"checkout -" works after a rebase -i A B' ' 161 git branch foodle main~1 && 162 git checkout main && 163 git checkout other && 164 git rebase main foodle && 165 git checkout - && 166 test_cmp_symbolic_HEAD_ref main 167 ' 168 169 test_done