Skip to content

Commit 4a2b50a

Browse files
committed
Merge branch 'km/t1400-modernization'
Code clean-up. * km/t1400-modernization: t1400: use test_when_finished for cleanup t1400: remove a set of unused output files t1400: use test_path_is_* helpers t1400: set core.logAllRefUpdates in "logged by touch" tests t1400: rename test descriptions to be unique
2 parents a026bde + 2405ed0 commit 4a2b50a

File tree

1 file changed

+78
-76
lines changed

1 file changed

+78
-76
lines changed

t/t1400-update-ref.sh

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -40,68 +40,68 @@ test_expect_success \
4040
"git update-ref $m $A &&
4141
test $A"' = $(cat .git/'"$m"')'
4242
test_expect_success \
43-
"create $m" \
43+
"create $m with oldvalue verification" \
4444
"git update-ref $m $B $A &&
4545
test $B"' = $(cat .git/'"$m"')'
4646
test_expect_success "fail to delete $m with stale ref" '
4747
test_must_fail git update-ref -d $m $A &&
4848
test $B = "$(cat .git/$m)"
4949
'
5050
test_expect_success "delete $m" '
51+
test_when_finished "rm -f .git/$m" &&
5152
git update-ref -d $m $B &&
52-
! test -f .git/$m
53+
test_path_is_missing .git/$m
5354
'
54-
rm -f .git/$m
5555

56-
test_expect_success "delete $m without oldvalue verification" "
56+
test_expect_success "delete $m without oldvalue verification" '
57+
test_when_finished "rm -f .git/$m" &&
5758
git update-ref $m $A &&
58-
test $A = \$(cat .git/$m) &&
59+
test $A = $(cat .git/$m) &&
5960
git update-ref -d $m &&
60-
! test -f .git/$m
61-
"
62-
rm -f .git/$m
61+
test_path_is_missing .git/$m
62+
'
6363

64-
test_expect_success \
65-
"fail to create $n" \
66-
"touch .git/$n_dir &&
67-
test_must_fail git update-ref $n $A >out 2>err"
68-
rm -f .git/$n_dir out err
64+
test_expect_success "fail to create $n" '
65+
test_when_finished "rm -f .git/$n_dir" &&
66+
touch .git/$n_dir &&
67+
test_must_fail git update-ref $n $A
68+
'
6969

7070
test_expect_success \
7171
"create $m (by HEAD)" \
7272
"git update-ref HEAD $A &&
7373
test $A"' = $(cat .git/'"$m"')'
7474
test_expect_success \
75-
"create $m (by HEAD)" \
75+
"create $m (by HEAD) with oldvalue verification" \
7676
"git update-ref HEAD $B $A &&
7777
test $B"' = $(cat .git/'"$m"')'
7878
test_expect_success "fail to delete $m (by HEAD) with stale ref" '
7979
test_must_fail git update-ref -d HEAD $A &&
8080
test $B = $(cat .git/$m)
8181
'
8282
test_expect_success "delete $m (by HEAD)" '
83+
test_when_finished "rm -f .git/$m" &&
8384
git update-ref -d HEAD $B &&
84-
! test -f .git/$m
85+
test_path_is_missing .git/$m
8586
'
86-
rm -f .git/$m
8787

8888
test_expect_success "deleting current branch adds message to HEAD's log" '
89+
test_when_finished "rm -f .git/$m" &&
8990
git update-ref $m $A &&
9091
git symbolic-ref HEAD $m &&
9192
git update-ref -m delete-$m -d $m &&
92-
! test -f .git/$m &&
93+
test_path_is_missing .git/$m &&
9394
grep "delete-$m$" .git/logs/HEAD
9495
'
95-
rm -f .git/$m
9696

9797
test_expect_success "deleting by HEAD adds message to HEAD's log" '
98+
test_when_finished "rm -f .git/$m" &&
9899
git update-ref $m $A &&
99100
git symbolic-ref HEAD $m &&
100101
git update-ref -m delete-by-head -d HEAD &&
101-
! test -f .git/$m &&
102+
test_path_is_missing .git/$m &&
102103
grep "delete-by-head$" .git/logs/HEAD
103104
'
104-
rm -f .git/$m
105105

106106
test_expect_success 'update-ref does not create reflogs by default' '
107107
test_when_finished "git update-ref -d $outside" &&
@@ -188,28 +188,29 @@ test_expect_success \
188188
"git update-ref HEAD $B $A &&
189189
test $B"' = $(cat .git/'"$m"')'
190190
test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
191+
test_when_finished "rm -f .git/$m" &&
191192
git update-ref -d HEAD $B &&
192193
! grep "$m" .git/packed-refs &&
193-
! test -f .git/$m
194+
test_path_is_missing .git/$m
194195
'
195-
rm -f .git/$m
196196

197197
cp -f .git/HEAD .git/HEAD.orig
198198
test_expect_success "delete symref without dereference" '
199+
test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
199200
git update-ref --no-deref -d HEAD &&
200-
! test -f .git/HEAD
201+
test_path_is_missing .git/HEAD
201202
'
202-
cp -f .git/HEAD.orig .git/HEAD
203203

204204
test_expect_success "delete symref without dereference when the referred ref is packed" '
205+
test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
205206
echo foo >foo.c &&
206207
git add foo.c &&
207208
git commit -m foo &&
208209
git pack-refs --all &&
209210
git update-ref --no-deref -d HEAD &&
210-
! test -f .git/HEAD
211+
test_path_is_missing .git/HEAD
211212
'
212-
cp -f .git/HEAD.orig .git/HEAD
213+
213214
git update-ref -d $m
214215

215216
test_expect_success 'update-ref -d is not confused by self-reference' '
@@ -241,94 +242,95 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
241242
test_expect_success '(not) create HEAD with old sha1' "
242243
test_must_fail git update-ref HEAD $A $B
243244
"
244-
test_expect_success "(not) prior created .git/$m" "
245-
! test -f .git/$m
246-
"
247-
rm -f .git/$m
245+
test_expect_success "(not) prior created .git/$m" '
246+
test_when_finished "rm -f .git/$m" &&
247+
test_path_is_missing .git/$m
248+
'
248249

249250
test_expect_success \
250251
"create HEAD" \
251252
"git update-ref HEAD $A"
252253
test_expect_success '(not) change HEAD with wrong SHA1' "
253254
test_must_fail git update-ref HEAD $B $Z
254255
"
255-
test_expect_success "(not) changed .git/$m" "
256-
! test $B"' = $(cat .git/'"$m"')
256+
test_expect_success "(not) changed .git/$m" '
257+
test_when_finished "rm -f .git/$m" &&
258+
! test $B = $(cat .git/$m)
257259
'
258-
rm -f .git/$m
259260

260261
rm -f .git/logs/refs/heads/master
261262
test_expect_success \
262263
"create $m (logged by touch)" \
263-
'GIT_COMMITTER_DATE="2005-05-26 23:30" \
264+
'test_config core.logAllRefUpdates false &&
265+
GIT_COMMITTER_DATE="2005-05-26 23:30" \
264266
git update-ref --create-reflog HEAD '"$A"' -m "Initial Creation" &&
265267
test '"$A"' = $(cat .git/'"$m"')'
266268
test_expect_success \
267269
"update $m (logged by touch)" \
268-
'GIT_COMMITTER_DATE="2005-05-26 23:31" \
270+
'test_config core.logAllRefUpdates false &&
271+
GIT_COMMITTER_DATE="2005-05-26 23:31" \
269272
git update-ref HEAD'" $B $A "'-m "Switch" &&
270273
test '"$B"' = $(cat .git/'"$m"')'
271274
test_expect_success \
272275
"set $m (logged by touch)" \
273-
'GIT_COMMITTER_DATE="2005-05-26 23:41" \
276+
'test_config core.logAllRefUpdates false &&
277+
GIT_COMMITTER_DATE="2005-05-26 23:41" \
274278
git update-ref HEAD'" $A &&
275279
test $A"' = $(cat .git/'"$m"')'
276280

277281
test_expect_success "empty directory removal" '
278282
git branch d1/d2/r1 HEAD &&
279283
git branch d1/r2 HEAD &&
280-
test -f .git/refs/heads/d1/d2/r1 &&
281-
test -f .git/logs/refs/heads/d1/d2/r1 &&
284+
test_path_is_file .git/refs/heads/d1/d2/r1 &&
285+
test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
282286
git branch -d d1/d2/r1 &&
283-
! test -e .git/refs/heads/d1/d2 &&
284-
! test -e .git/logs/refs/heads/d1/d2 &&
285-
test -f .git/refs/heads/d1/r2 &&
286-
test -f .git/logs/refs/heads/d1/r2
287+
test_path_is_missing .git/refs/heads/d1/d2 &&
288+
test_path_is_missing .git/logs/refs/heads/d1/d2 &&
289+
test_path_is_file .git/refs/heads/d1/r2 &&
290+
test_path_is_file .git/logs/refs/heads/d1/r2
287291
'
288292

289293
test_expect_success "symref empty directory removal" '
290294
git branch e1/e2/r1 HEAD &&
291295
git branch e1/r2 HEAD &&
292296
git checkout e1/e2/r1 &&
293297
test_when_finished "git checkout master" &&
294-
test -f .git/refs/heads/e1/e2/r1 &&
295-
test -f .git/logs/refs/heads/e1/e2/r1 &&
298+
test_path_is_file .git/refs/heads/e1/e2/r1 &&
299+
test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
296300
git update-ref -d HEAD &&
297-
! test -e .git/refs/heads/e1/e2 &&
298-
! test -e .git/logs/refs/heads/e1/e2 &&
299-
test -f .git/refs/heads/e1/r2 &&
300-
test -f .git/logs/refs/heads/e1/r2 &&
301-
test -f .git/logs/HEAD
301+
test_path_is_missing .git/refs/heads/e1/e2 &&
302+
test_path_is_missing .git/logs/refs/heads/e1/e2 &&
303+
test_path_is_file .git/refs/heads/e1/r2 &&
304+
test_path_is_file .git/logs/refs/heads/e1/r2 &&
305+
test_path_is_file .git/logs/HEAD
302306
'
303307

304308
cat >expect <<EOF
305309
$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
306310
$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
307311
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
308312
EOF
309-
test_expect_success \
310-
"verifying $m's log" \
311-
"test_cmp expect .git/logs/$m"
312-
rm -rf .git/$m .git/logs expect
313-
314-
test_expect_success \
315-
'enable core.logAllRefUpdates' \
316-
'git config core.logAllRefUpdates true &&
317-
test true = $(git config --bool --get core.logAllRefUpdates)'
313+
test_expect_success "verifying $m's log (logged by touch)" '
314+
test_when_finished "rm -rf .git/$m .git/logs expect" &&
315+
test_cmp expect .git/logs/$m
316+
'
318317

319318
test_expect_success \
320319
"create $m (logged by config)" \
321-
'GIT_COMMITTER_DATE="2005-05-26 23:32" \
320+
'test_config core.logAllRefUpdates true &&
321+
GIT_COMMITTER_DATE="2005-05-26 23:32" \
322322
git update-ref HEAD'" $A "'-m "Initial Creation" &&
323323
test '"$A"' = $(cat .git/'"$m"')'
324324
test_expect_success \
325325
"update $m (logged by config)" \
326-
'GIT_COMMITTER_DATE="2005-05-26 23:33" \
326+
'test_config core.logAllRefUpdates true &&
327+
GIT_COMMITTER_DATE="2005-05-26 23:33" \
327328
git update-ref HEAD'" $B $A "'-m "Switch" &&
328329
test '"$B"' = $(cat .git/'"$m"')'
329330
test_expect_success \
330331
"set $m (logged by config)" \
331-
'GIT_COMMITTER_DATE="2005-05-26 23:43" \
332+
'test_config core.logAllRefUpdates true &&
333+
GIT_COMMITTER_DATE="2005-05-26 23:43" \
332334
git update-ref HEAD '"$A &&
333335
test $A"' = $(cat .git/'"$m"')'
334336

@@ -338,9 +340,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
338340
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
339341
EOF
340342
test_expect_success \
341-
"verifying $m's log" \
342-
'test_cmp expect .git/logs/$m'
343-
rm -f .git/$m .git/logs/$m expect
343+
"verifying $m's log (logged by config)" \
344+
'test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
345+
test_cmp expect .git/logs/$m'
344346

345347
git update-ref $m $D
346348
cat >.git/logs/$m <<EOF
@@ -356,55 +358,55 @@ gd="Thu, 26 May 2005 18:33:00 -0500"
356358
ld="Thu, 26 May 2005 18:43:00 -0500"
357359
test_expect_success \
358360
'Query "master@{May 25 2005}" (before history)' \
359-
'rm -f o e &&
361+
'test_when_finished "rm -f o e" &&
360362
git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
361363
test '"$C"' = $(cat o) &&
362364
test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
363365
test_expect_success \
364366
"Query master@{2005-05-25} (before history)" \
365-
'rm -f o e &&
367+
'test_when_finished "rm -f o e" &&
366368
git rev-parse --verify master@{2005-05-25} >o 2>e &&
367369
test '"$C"' = $(cat o) &&
368370
echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
369371
test_expect_success \
370372
'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
371-
'rm -f o e &&
373+
'test_when_finished "rm -f o e" &&
372374
git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
373375
test '"$C"' = $(cat o) &&
374376
test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
375377
test_expect_success \
376378
'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
377-
'rm -f o e &&
379+
'test_when_finished "rm -f o e" &&
378380
git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
379381
test '"$C"' = $(cat o) &&
380382
test "" = "$(cat e)"'
381383
test_expect_success \
382384
'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
383-
'rm -f o e &&
385+
'test_when_finished "rm -f o e" &&
384386
git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
385387
test '"$A"' = $(cat o) &&
386388
test "" = "$(cat e)"'
387389
test_expect_success \
388390
'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
389-
'rm -f o e &&
391+
'test_when_finished "rm -f o e" &&
390392
git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
391393
test '"$B"' = $(cat o) &&
392394
test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
393395
test_expect_success \
394396
'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
395-
'rm -f o e &&
397+
'test_when_finished "rm -f o e" &&
396398
git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
397399
test '"$Z"' = $(cat o) &&
398400
test "" = "$(cat e)"'
399401
test_expect_success \
400402
'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
401-
'rm -f o e &&
403+
'test_when_finished "rm -f o e" &&
402404
git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
403405
test '"$E"' = $(cat o) &&
404406
test "" = "$(cat e)"'
405407
test_expect_success \
406408
'Query "master@{2005-05-28}" (past end of history)' \
407-
'rm -f o e &&
409+
'test_when_finished "rm -f o e" &&
408410
git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
409411
test '"$D"' = $(cat o) &&
410412
test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
@@ -414,7 +416,8 @@ rm -f .git/$m .git/logs/$m expect
414416

415417
test_expect_success \
416418
'creating initial files' \
417-
'echo TEST >F &&
419+
'test_when_finished rm -f M &&
420+
echo TEST >F &&
418421
git add F &&
419422
GIT_AUTHOR_DATE="2005-05-26 23:30" \
420423
GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
@@ -432,8 +435,7 @@ test_expect_success \
432435
echo $h_TEST >.git/MERGE_HEAD &&
433436
GIT_AUTHOR_DATE="2005-05-26 23:45" \
434437
GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
435-
h_MERGED=$(git rev-parse --verify HEAD) &&
436-
rm -f M'
438+
h_MERGED=$(git rev-parse --verify HEAD)'
437439

438440
cat >expect <<EOF
439441
$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add

0 commit comments

Comments
 (0)