@@ -60,66 +60,59 @@ 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
69
test_expect_success ' checkout -b to a new branch, set to an explicit ref' '
67
- git checkout branch1 &&
68
- git branch -D branch2 &&
69
-
70
+ test_when_finished "
71
+ git checkout branch1 &&
72
+ test_might_fail git branch -D branch2" &&
70
73
do_checkout branch2 $HEAD1
71
74
'
72
75
73
76
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
77
setup_dirty_unmergeable &&
80
78
test_must_fail do_checkout branch2 $HEAD1 &&
81
79
test_dirty_unmergeable
82
80
'
83
81
84
82
test_expect_success ' checkout -f -b to a new branch with unmergeable changes discards changes' '
83
+ test_when_finished "
84
+ git checkout branch1 &&
85
+ test_might_fail git branch -D branch2" &&
86
+
85
87
# still dirty and on branch1
86
88
do_checkout branch2 $HEAD1 "-f -b" &&
87
89
test_must_fail test_dirty_unmergeable
88
90
'
89
91
90
92
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 &&
93
+ test_when_finished "
94
+ git reset --hard &&
95
+ git checkout branch1 &&
96
+ test_might_fail git branch -D branch2" &&
95
97
96
98
setup_dirty_mergeable &&
97
99
do_checkout branch2 $HEAD1 &&
98
100
test_dirty_mergeable
99
101
'
100
102
101
103
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
-
104
+ test_when_finished git reset --hard HEAD &&
110
105
setup_dirty_mergeable &&
111
106
do_checkout branch2 $HEAD1 "-f -b" &&
112
107
test_must_fail test_dirty_mergeable
113
108
'
114
109
115
110
test_expect_success ' checkout -b to an existing branch fails' '
116
- git reset --hard HEAD &&
117
-
111
+ test_when_finished git reset --hard HEAD &&
118
112
test_must_fail do_checkout branch2 $HEAD2
119
113
'
120
114
121
115
test_expect_success ' checkout -b to @{-1} fails with the right branch name' '
122
- git reset --hard HEAD &&
123
116
git checkout branch1 &&
124
117
git checkout branch2 &&
125
118
echo >expect "fatal: A branch named ' \' ' branch1' \' ' already exists." &&
@@ -160,6 +153,7 @@ test_expect_success 'checkout -f -B to an existing branch with unmergeable chang
160
153
'
161
154
162
155
test_expect_success ' checkout -B to an existing branch preserves mergeable changes' '
156
+ test_when_finished git reset --hard &&
163
157
git checkout branch1 &&
164
158
165
159
setup_dirty_mergeable &&
@@ -168,9 +162,6 @@ test_expect_success 'checkout -B to an existing branch preserves mergeable chang
168
162
'
169
163
170
164
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
165
git checkout branch1 &&
175
166
176
167
setup_dirty_mergeable &&
0 commit comments