Skip to content

Commit 5d27485

Browse files
jrngitster
authored andcommitted
t4150 (am): futureproof against failing tests
Most tests in t4150 begin by navigating to a sane state and applying some patch: git checkout first && git am patch1 If a previous test left behind unmerged files or a .git/rebase-apply directory, they are untouched and the test fails, causing later tests to fail, too. This is not a problem in practice because none of the tests leave a mess behind. But as a futureproofing measure, it is still best to avoid the problem and clean up at the start of each test. In particular, this simplifies the process of adding new tests that are known to fail. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 800f110 commit 5d27485

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

t/t4150-am.sh

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ test_expect_success setup '
122122
'
123123

124124
test_expect_success 'am applies patch correctly' '
125+
rm -fr .git/rebase-apply &&
126+
git reset --hard &&
125127
git checkout first &&
126128
test_tick &&
127129
git am <patch1 &&
@@ -132,6 +134,8 @@ test_expect_success 'am applies patch correctly' '
132134
'
133135

134136
test_expect_success 'am applies patch e-mail not in a mbox' '
137+
rm -fr .git/rebase-apply &&
138+
git reset --hard &&
135139
git checkout first &&
136140
git am patch1.eml &&
137141
! test -d .git/rebase-apply &&
@@ -141,6 +145,8 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
141145
'
142146

143147
test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
148+
rm -fr .git/rebase-apply &&
149+
git reset --hard &&
144150
git checkout first &&
145151
git am patch1-crlf.eml &&
146152
! test -d .git/rebase-apply &&
@@ -165,6 +171,8 @@ compare () {
165171

166172
test_expect_success 'am changes committer and keeps author' '
167173
test_tick &&
174+
rm -fr .git/rebase-apply &&
175+
git reset --hard &&
168176
git checkout first &&
169177
git am patch2 &&
170178
! test -d .git/rebase-apply &&
@@ -178,6 +186,8 @@ test_expect_success 'am changes committer and keeps author' '
178186
'
179187

180188
test_expect_success 'am --signoff adds Signed-off-by: line' '
189+
rm -fr .git/rebase-apply &&
190+
git reset --hard &&
181191
git checkout -b master2 first &&
182192
git am --signoff <patch2 &&
183193
printf "%s\n" "$signoff" >expected &&
@@ -198,6 +208,8 @@ test_expect_success 'am stays in branch' '
198208
test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
199209
git format-patch --stdout HEAD^ >patch3 &&
200210
sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
211+
rm -fr .git/rebase-apply &&
212+
git reset --hard &&
201213
git checkout HEAD^ &&
202214
git am --signoff patch4 &&
203215
git cat-file commit HEAD >actual &&
@@ -211,6 +223,8 @@ test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
211223
'
212224

213225
test_expect_success 'am --keep really keeps the subject' '
226+
rm -fr .git/rebase-apply &&
227+
git reset --hard &&
214228
git checkout HEAD^ &&
215229
git am --keep patch4 &&
216230
! test -d .git/rebase-apply &&
@@ -219,6 +233,8 @@ test_expect_success 'am --keep really keeps the subject' '
219233
'
220234

221235
test_expect_success 'am -3 falls back to 3-way merge' '
236+
rm -fr .git/rebase-apply &&
237+
git reset --hard &&
222238
git checkout -b lorem2 master2 &&
223239
sed -n -e "3,\$p" msg >file &&
224240
head -n 9 msg >>file &&
@@ -231,6 +247,7 @@ test_expect_success 'am -3 falls back to 3-way merge' '
231247
'
232248

233249
test_expect_success 'am -3 -q is quiet' '
250+
rm -fr .git/rebase-apply &&
234251
git reset master2 --hard &&
235252
sed -n -e "3,\$p" msg >file &&
236253
head -n 9 msg >>file &&
@@ -242,6 +259,8 @@ test_expect_success 'am -3 -q is quiet' '
242259
'
243260

244261
test_expect_success 'am pauses on conflict' '
262+
rm -fr .git/rebase-apply &&
263+
git reset --hard &&
245264
git checkout lorem2^^ &&
246265
test_must_fail git am lorem-move.patch &&
247266
test -d .git/rebase-apply
@@ -257,6 +276,8 @@ test_expect_success 'am --skip works' '
257276

258277
test_expect_success 'am --resolved works' '
259278
echo goodbye >expected &&
279+
rm -fr .git/rebase-apply &&
280+
git reset --hard &&
260281
git checkout lorem2^^ &&
261282
test_must_fail git am lorem-move.patch &&
262283
test -d .git/rebase-apply &&
@@ -268,18 +289,25 @@ test_expect_success 'am --resolved works' '
268289
'
269290

270291
test_expect_success 'am takes patches from a Pine mailbox' '
292+
rm -fr .git/rebase-apply &&
293+
git reset --hard &&
271294
git checkout first &&
272295
cat pine patch1 | git am &&
273296
! test -d .git/rebase-apply &&
274297
git diff --exit-code master^..HEAD
275298
'
276299

277300
test_expect_success 'am fails on mail without patch' '
301+
rm -fr .git/rebase-apply &&
302+
git reset --hard &&
278303
test_must_fail git am <failmail &&
279-
rm -r .git/rebase-apply/
304+
git am --abort &&
305+
! test -d .git/rebase-apply
280306
'
281307

282308
test_expect_success 'am fails on empty patch' '
309+
rm -fr .git/rebase-apply &&
310+
git reset --hard &&
283311
echo "---" >>failmail &&
284312
test_must_fail git am <failmail &&
285313
git am --skip &&
@@ -288,6 +316,8 @@ test_expect_success 'am fails on empty patch' '
288316

289317
test_expect_success 'am works from stdin in subdirectory' '
290318
rm -fr subdir &&
319+
rm -fr .git/rebase-apply &&
320+
git reset --hard &&
291321
git checkout first &&
292322
(
293323
mkdir -p subdir &&
@@ -299,6 +329,8 @@ test_expect_success 'am works from stdin in subdirectory' '
299329

300330
test_expect_success 'am works from file (relative path given) in subdirectory' '
301331
rm -fr subdir &&
332+
rm -fr .git/rebase-apply &&
333+
git reset --hard &&
302334
git checkout first &&
303335
(
304336
mkdir -p subdir &&
@@ -310,6 +342,8 @@ test_expect_success 'am works from file (relative path given) in subdirectory' '
310342

311343
test_expect_success 'am works from file (absolute path given) in subdirectory' '
312344
rm -fr subdir &&
345+
rm -fr .git/rebase-apply &&
346+
git reset --hard &&
313347
git checkout first &&
314348
P=$(pwd) &&
315349
(
@@ -321,6 +355,8 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
321355
'
322356

323357
test_expect_success 'am --committer-date-is-author-date' '
358+
rm -fr .git/rebase-apply &&
359+
git reset --hard &&
324360
git checkout first &&
325361
test_tick &&
326362
git am --committer-date-is-author-date patch1 &&
@@ -331,6 +367,8 @@ test_expect_success 'am --committer-date-is-author-date' '
331367
'
332368

333369
test_expect_success 'am without --committer-date-is-author-date' '
370+
rm -fr .git/rebase-apply &&
371+
git reset --hard &&
334372
git checkout first &&
335373
test_tick &&
336374
git am patch1 &&
@@ -345,6 +383,8 @@ test_expect_success 'am without --committer-date-is-author-date' '
345383
# by test_tick that uses -0700 timezone; if this feature does not
346384
# work, we will see that instead of +0000.
347385
test_expect_success 'am --ignore-date' '
386+
rm -fr .git/rebase-apply &&
387+
git reset --hard &&
348388
git checkout first &&
349389
test_tick &&
350390
git am --ignore-date patch1 &&
@@ -355,6 +395,8 @@ test_expect_success 'am --ignore-date' '
355395

356396
test_expect_success 'am into an unborn branch' '
357397
git rev-parse first^{tree} >expected &&
398+
rm -fr .git/rebase-apply &&
399+
git reset --hard &&
358400
rm -fr subdir &&
359401
mkdir subdir &&
360402
git format-patch --numbered-files -o subdir -1 first &&
@@ -371,6 +413,8 @@ test_expect_success 'am into an unborn branch' '
371413
'
372414

373415
test_expect_success 'am newline in subject' '
416+
rm -fr .git/rebase-apply &&
417+
git reset --hard &&
374418
git checkout first &&
375419
test_tick &&
376420
sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
@@ -379,6 +423,8 @@ test_expect_success 'am newline in subject' '
379423
'
380424

381425
test_expect_success 'am -q is quiet' '
426+
rm -fr .git/rebase-apply &&
427+
git reset --hard &&
382428
git checkout first &&
383429
test_tick &&
384430
git am -q <patch1 >output.out 2>&1 &&

0 commit comments

Comments
 (0)