t1400: split up generic reflog tests from the reffile-specific ones

We have a bunch of tests in t1400 that check whether we correctly read reflog entries. These tests create the reflog by manually writing to the respective loose file, which makes them specific to the files backend. But while some of them do indeed exercise very specific edge cases in the reffiles backend, most of the tests exercise generic functionality that should be common to all backends. Unfortunately, we can't easily adapt all of the tests to work with all backends. Instead, split out the reffile-specific tests from the ones that should work with all backends and refactor the generic ones to not write to the on-disk files directly anymore. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 29, 2023 at 08:24 UTC db7288b321d5429a6a02b47f27907a519300c6e6
1 file changed +35 -6
t/t1400-update-ref.sh
+35 -6
@@ -354,14 +354,28 @@ test_expect_success "verifying $m's log (logged by config)" '
354 '
355
356 test_expect_success 'set up for querying the reflog' '
357 + git update-ref -d $m &&
358 + test-tool ref-store main delete-reflog $m &&
359 +
360 + GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $C &&
361 + GIT_COMMITTER_DATE="1117150350 -0500" git update-ref $m $A &&
362 + GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
363 + GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
364 + GIT_COMMITTER_DATE="1117150980 -0500" git update-ref $m $E &&
365 git update-ref $m $D &&
358 - cat >.git/logs/$m <<-EOF
366 + # Delete the last reflog entry so that the tip of m and the reflog for
367 + # it disagree.
368 + git reflog delete $m@{0} &&
369 +
370 + cat >expect <<-EOF &&
371 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
372 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
373 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
362 - $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
363 - $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
374 + $B $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
375 + $F $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
376 EOF
377 + test-tool ref-store main for-each-reflog-ent $m >actual &&
378 + test_cmp expect actual
379 '
380
381 ed="Thu, 26 May 2005 18:32:00 -0500"
@@ -409,13 +423,12 @@ test_expect_success 'Query "main@{2005-05-26 23:33:01}" (middle of history with
423 test_when_finished "rm -f o e" &&
424 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
425 echo "$B" >expect &&
412 - test_cmp expect o &&
413 - test_grep -F "warning: log for ref $m has gap after $gd" e
426 + test_cmp expect o
427 '
428 test_expect_success 'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
429 test_when_finished "rm -f o e" &&
430 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
418 - echo "$Z" >expect &&
431 + echo "$F" >expect &&
432 test_cmp expect o &&
433 test_must_be_empty e
434 '
@@ -436,6 +449,22 @@ test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
449
450 rm -f .git/$m .git/logs/$m expect
451
452 +test_expect_success REFFILES 'query reflog with gap' '
453 + test_when_finished "git update-ref -d $m" &&
454 +
455 + git update-ref $m $F &&
456 + cat >.git/logs/$m <<-EOF &&
457 + $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
458 + $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
459 + $D $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
460 + EOF
461 +
462 + git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr &&
463 + echo "$B" >expect &&
464 + test_cmp expect actual &&
465 + test_grep -F "warning: log for ref $m has gap after $gd" stderr
466 +'
467 +
468 test_expect_success 'creating initial files' '
469 test_when_finished rm -f M &&
470 echo TEST >F &&