@@ -60,66 +60,66 @@ test_expect_success 'setup' '
60
60
'
61
61
62
62
test_expect_success ' checkout -b to a new branch, set to HEAD' '
63
+ test_when_finished "
64
+ git checkout branch1 &&
65
+ test_might_fail git branch -D branch2" &&
63
66
do_checkout branch2
64
67
'
65
68
66
- test_expect_success ' checkout -b to a new branch, set to an explicit ref' '
67
- git checkout branch1 &&
68
- git branch -D branch2 &&
69
+ test_expect_success ' checkout -b to a merge base' '
70
+ test_when_finished "
71
+ git checkout branch1 &&
72
+ test_might_fail git branch -D branch2" &&
73
+ git checkout -b branch2 branch1...
74
+ '
69
75
76
+ test_expect_success ' checkout -b to a new branch, set to an explicit ref' '
77
+ test_when_finished "
78
+ git checkout branch1 &&
79
+ test_might_fail git branch -D branch2" &&
70
80
do_checkout branch2 $HEAD1
71
81
'
72
82
73
83
test_expect_success ' checkout -b to a new branch with unmergeable changes fails' '
74
- git checkout branch1 &&
75
-
76
- # clean up from previous test
77
- git branch -D branch2 &&
78
-
79
84
setup_dirty_unmergeable &&
80
85
test_must_fail do_checkout branch2 $HEAD1 &&
81
86
test_dirty_unmergeable
82
87
'
83
88
84
89
test_expect_success ' checkout -f -b to a new branch with unmergeable changes discards changes' '
90
+ test_when_finished "
91
+ git checkout branch1 &&
92
+ test_might_fail git branch -D branch2" &&
93
+
85
94
# still dirty and on branch1
86
95
do_checkout branch2 $HEAD1 "-f -b" &&
87
96
test_must_fail test_dirty_unmergeable
88
97
'
89
98
90
99
test_expect_success ' checkout -b to a new branch preserves mergeable changes' '
91
- git checkout branch1 &&
92
-
93
- # clean up from previous test
94
- git branch -D branch2 &&
100
+ test_when_finished "
101
+ git reset --hard &&
102
+ git checkout branch1 &&
103
+ test_might_fail git branch -D branch2" &&
95
104
96
105
setup_dirty_mergeable &&
97
106
do_checkout branch2 $HEAD1 &&
98
107
test_dirty_mergeable
99
108
'
100
109
101
110
test_expect_success ' checkout -f -b to a new branch with mergeable changes discards changes' '
102
- # clean up from previous test
103
- git reset --hard &&
104
-
105
- git checkout branch1 &&
106
-
107
- # clean up from previous test
108
- git branch -D branch2 &&
109
-
111
+ test_when_finished git reset --hard HEAD &&
110
112
setup_dirty_mergeable &&
111
113
do_checkout branch2 $HEAD1 "-f -b" &&
112
114
test_must_fail test_dirty_mergeable
113
115
'
114
116
115
117
test_expect_success ' checkout -b to an existing branch fails' '
116
- git reset --hard HEAD &&
117
-
118
+ test_when_finished git reset --hard HEAD &&
118
119
test_must_fail do_checkout branch2 $HEAD2
119
120
'
120
121
121
122
test_expect_success ' checkout -b to @{-1} fails with the right branch name' '
122
- git reset --hard HEAD &&
123
123
git checkout branch1 &&
124
124
git checkout branch2 &&
125
125
echo >expect "fatal: A branch named ' \' ' branch1' \' ' already exists." &&
@@ -133,6 +133,12 @@ test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '
133
133
do_checkout branch2 "" -B
134
134
'
135
135
136
+ test_expect_success ' checkout -B to a merge base' '
137
+ git checkout branch1 &&
138
+
139
+ git checkout -B branch2 branch1...
140
+ '
141
+
136
142
test_expect_success ' checkout -B to an existing branch from detached HEAD resets branch to HEAD' '
137
143
git checkout $(git rev-parse --verify HEAD) &&
138
144
@@ -160,6 +166,7 @@ test_expect_success 'checkout -f -B to an existing branch with unmergeable chang
160
166
'
161
167
162
168
test_expect_success ' checkout -B to an existing branch preserves mergeable changes' '
169
+ test_when_finished git reset --hard &&
163
170
git checkout branch1 &&
164
171
165
172
setup_dirty_mergeable &&
@@ -168,9 +175,6 @@ test_expect_success 'checkout -B to an existing branch preserves mergeable chang
168
175
'
169
176
170
177
test_expect_success ' checkout -f -B to an existing branch with mergeable changes discards changes' '
171
- # clean up from previous test
172
- git reset --hard &&
173
-
174
178
git checkout branch1 &&
175
179
176
180
setup_dirty_mergeable &&
0 commit comments