t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t2012-checkout-last.sh
blob4b6372f4c3e946c26a490698335a821cff5701f2
1 #!/bin/sh
3 test_description='checkout can switch to last branch and merge base'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 test_commit initial world hello &&
13 git branch other &&
14 test_commit --append second world "hello again"
17 test_expect_success '"checkout -" does not work initially' '
18 test_must_fail git checkout -
21 test_expect_success 'first branch switch' '
22 git checkout other
25 test_cmp_symbolic_HEAD_ref () {
26 echo refs/heads/"$1" >expect &&
27 git symbolic-ref HEAD >actual &&
28 test_cmp expect actual
31 test_expect_success '"checkout -" switches back' '
32 git checkout - &&
33 test_cmp_symbolic_HEAD_ref main
36 test_expect_success '"checkout -" switches forth' '
37 git checkout - &&
38 test_cmp_symbolic_HEAD_ref other
41 test_expect_success 'detach HEAD' '
42 git checkout $(git rev-parse HEAD)
45 test_expect_success '"checkout -" attaches again' '
46 git checkout - &&
47 test_cmp_symbolic_HEAD_ref other
50 test_expect_success '"checkout -" detaches again' '
51 git checkout - &&
53 git rev-parse other >expect &&
54 git rev-parse HEAD >actual &&
55 test_cmp expect actual &&
57 test_must_fail git symbolic-ref HEAD
60 test_expect_success 'more switches' '
61 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
63 git checkout -b branch$i || return 1
64 done
67 more_switches () {
68 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
70 git checkout branch$i || return 1
71 done
74 test_expect_success 'switch to the last' '
75 more_switches &&
76 git checkout @{-1} &&
77 test_cmp_symbolic_HEAD_ref branch2
80 test_expect_success 'switch to second from the last' '
81 more_switches &&
82 git checkout @{-2} &&
83 test_cmp_symbolic_HEAD_ref branch3
86 test_expect_success 'switch to third from the last' '
87 more_switches &&
88 git checkout @{-3} &&
89 test_cmp_symbolic_HEAD_ref branch4
92 test_expect_success 'switch to fourth from the last' '
93 more_switches &&
94 git checkout @{-4} &&
95 test_cmp_symbolic_HEAD_ref branch5
98 test_expect_success 'switch to twelfth from the last' '
99 more_switches &&
100 git checkout @{-12} &&
101 test_cmp_symbolic_HEAD_ref branch13
104 test_expect_success 'merge base test setup' '
105 git checkout -b another other &&
106 test_commit --append third world "hello again"
109 test_expect_success 'another...main' '
110 git checkout another &&
111 git checkout another...main &&
113 git rev-parse --verify main^ >expect &&
114 git rev-parse --verify HEAD >actual &&
115 test_cmp expect actual
118 test_expect_success '...main' '
119 git checkout another &&
120 git checkout ...main &&
122 git rev-parse --verify main^ >expect &&
123 git rev-parse --verify HEAD >actual &&
124 test_cmp expect actual
127 test_expect_success 'main...' '
128 git checkout another &&
129 git checkout main... &&
131 git rev-parse --verify main^ >expect &&
132 git rev-parse --verify HEAD >actual &&
133 test_cmp expect actual
136 test_expect_success '"checkout -" works after a rebase A' '
137 git checkout main &&
138 git checkout other &&
139 git rebase main &&
140 git checkout - &&
141 test_cmp_symbolic_HEAD_ref main
144 test_expect_success '"checkout -" works after a rebase A B' '
145 git branch moodle main~1 &&
146 git checkout main &&
147 git checkout other &&
148 git rebase main moodle &&
149 git checkout - &&
150 test_cmp_symbolic_HEAD_ref main
153 test_expect_success '"checkout -" works after a rebase -i A' '
154 git checkout main &&
155 git checkout other &&
156 git rebase -i main &&
157 git checkout - &&
158 test_cmp_symbolic_HEAD_ref main
161 test_expect_success '"checkout -" works after a rebase -i A B' '
162 git branch foodle main~1 &&
163 git checkout main &&
164 git checkout other &&
165 git rebase main foodle &&
166 git checkout - &&
167 test_cmp_symbolic_HEAD_ref main
170 test_done