]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2012-checkout-last.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t2012-checkout-last.sh
CommitLineData
696acf45
TR
1#!/bin/sh
2
619a644d 3test_description='checkout can switch to last branch and merge base'
696acf45 4
883b98ef 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
696acf45
TR
8. ./test-lib.sh
9
10test_expect_success 'setup' '
f5d79bf7 11 test_commit initial world hello &&
696acf45 12 git branch other &&
f5d79bf7 13 test_commit --append second world "hello again"
696acf45
TR
14'
15
16test_expect_success '"checkout -" does not work initially' '
17 test_must_fail git checkout -
18'
19
20test_expect_success 'first branch switch' '
21 git checkout other
22'
23
24test_expect_success '"checkout -" switches back' '
25 git checkout - &&
883b98ef 26 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
696acf45
TR
27'
28
29test_expect_success '"checkout -" switches forth' '
30 git checkout - &&
31 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
32'
33
34test_expect_success 'detach HEAD' '
35 git checkout $(git rev-parse HEAD)
36'
37
38test_expect_success '"checkout -" attaches again' '
39 git checkout - &&
40 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
41'
42
43test_expect_success '"checkout -" detaches again' '
44 git checkout - &&
45 test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
46 test_must_fail git symbolic-ref HEAD
47'
48
c2883e62
JH
49test_expect_success 'more switches' '
50 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
51 do
db5875aa 52 git checkout -b branch$i || return 1
c2883e62
JH
53 done
54'
55
56more_switches () {
57 for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
58 do
db5875aa 59 git checkout branch$i || return 1
c2883e62
JH
60 done
61}
62
63test_expect_success 'switch to the last' '
64 more_switches &&
65 git checkout @{-1} &&
66 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
67'
68
69test_expect_success 'switch to second from the last' '
70 more_switches &&
71 git checkout @{-2} &&
72 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
73'
74
75test_expect_success 'switch to third from the last' '
76 more_switches &&
77 git checkout @{-3} &&
78 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
79'
80
81test_expect_success 'switch to fourth from the last' '
82 more_switches &&
83 git checkout @{-4} &&
84 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
85'
86
87test_expect_success 'switch to twelfth from the last' '
88 more_switches &&
89 git checkout @{-12} &&
90 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
91'
92
619a644d
JH
93test_expect_success 'merge base test setup' '
94 git checkout -b another other &&
f5d79bf7 95 test_commit --append third world "hello again"
619a644d
JH
96'
97
883b98ef 98test_expect_success 'another...main' '
619a644d 99 git checkout another &&
883b98ef
JS
100 git checkout another...main &&
101 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
619a644d
JH
102'
103
883b98ef 104test_expect_success '...main' '
619a644d 105 git checkout another &&
883b98ef
JS
106 git checkout ...main &&
107 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
619a644d
JH
108'
109
883b98ef 110test_expect_success 'main...' '
619a644d 111 git checkout another &&
883b98ef
JS
112 git checkout main... &&
113 test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
619a644d
JH
114'
115
3bed291a 116test_expect_success '"checkout -" works after a rebase A' '
883b98ef 117 git checkout main &&
89f2fea4 118 git checkout other &&
883b98ef 119 git rebase main &&
89f2fea4 120 git checkout - &&
883b98ef 121 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
89f2fea4
RR
122'
123
3bed291a 124test_expect_success '"checkout -" works after a rebase A B' '
883b98ef
JS
125 git branch moodle main~1 &&
126 git checkout main &&
89f2fea4 127 git checkout other &&
883b98ef 128 git rebase main moodle &&
89f2fea4 129 git checkout - &&
883b98ef 130 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
89f2fea4
RR
131'
132
3bed291a 133test_expect_success '"checkout -" works after a rebase -i A' '
883b98ef 134 git checkout main &&
89f2fea4 135 git checkout other &&
883b98ef 136 git rebase -i main &&
89f2fea4 137 git checkout - &&
883b98ef 138 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
89f2fea4
RR
139'
140
3bed291a 141test_expect_success '"checkout -" works after a rebase -i A B' '
883b98ef
JS
142 git branch foodle main~1 &&
143 git checkout main &&
89f2fea4 144 git checkout other &&
883b98ef 145 git rebase main foodle &&
89f2fea4 146 git checkout - &&
883b98ef 147 test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
89f2fea4
RR
148'
149
696acf45 150test_done