Skip to content

Commit 668e31c

Browse files
pks-tgitster
authored andcommitted
t: convert tests to not access reflog via the filesystem
Some of our tests reach directly into the filesystem in order to both read or modify the reflog, which will break once we have a second reference backend in our codebase that stores reflogs differently. Refactor these tests to either use git-reflog(1) or the ref-store test helper. Note that the refactoring to use git-reflog(1) also requires us to adapt our expectations in some cases where we previously verified the exact on-disk log entries. This seems like an acceptable tradeoff though to ensure that different backends have the same user-visible behaviour as any user would typically use git-reflog(1) anyway to access the logs. Any backend-specific verification of the written on-disk format should be implemented in a separate, backend-specific test. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2393711 commit 668e31c

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

t/t1400-update-ref.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ test_expect_success "deleting current branch adds message to HEAD's log" '
9090
git symbolic-ref HEAD $m &&
9191
git update-ref -m delete-$m -d $m &&
9292
test_must_fail git show-ref --verify -q $m &&
93-
grep "delete-$m$" .git/logs/HEAD
93+
test-tool ref-store main for-each-reflog-ent HEAD >actual &&
94+
grep "delete-$m$" actual
9495
'
9596

9697
test_expect_success "deleting by HEAD adds message to HEAD's log" '
@@ -99,7 +100,8 @@ test_expect_success "deleting by HEAD adds message to HEAD's log" '
99100
git symbolic-ref HEAD $m &&
100101
git update-ref -m delete-by-head -d HEAD &&
101102
test_must_fail git show-ref --verify -q $m &&
102-
grep "delete-by-head$" .git/logs/HEAD
103+
test-tool ref-store main for-each-reflog-ent HEAD >actual &&
104+
grep "delete-by-head$" actual
103105
'
104106

105107
test_expect_success 'update-ref does not create reflogs by default' '
@@ -130,7 +132,7 @@ test_expect_success 'creates no reflog in bare repository' '
130132

131133
test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
132134
test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
133-
rm $bare/logs/$m" &&
135+
test-tool ref-store main delete-reflog $m" &&
134136
git -C $bare config core.logAllRefUpdates true &&
135137
git -C $bare update-ref $m $bareB &&
136138
git -C $bare rev-parse $bareB >expect &&
@@ -263,7 +265,10 @@ test_expect_success "(not) changed .git/$m" '
263265
! test $B = $(git show-ref -s --verify $m)
264266
'
265267

266-
rm -f .git/logs/refs/heads/main
268+
test_expect_success "clean up reflog" '
269+
test-tool ref-store main delete-reflog $m
270+
'
271+
267272
test_expect_success "create $m (logged by touch)" '
268273
test_config core.logAllRefUpdates false &&
269274
GIT_COMMITTER_DATE="2005-05-26 23:30" \
@@ -316,7 +321,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
316321
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
317322
EOF
318323
test_expect_success "verifying $m's log (logged by touch)" '
319-
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
324+
test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
320325
test-tool ref-store main for-each-reflog-ent $m >actual &&
321326
test_cmp actual expect
322327
'
@@ -346,7 +351,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
346351
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
347352
EOF
348353
test_expect_success "verifying $m's log (logged by config)" '
349-
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
354+
test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
350355
test-tool ref-store main for-each-reflog-ent $m >actual &&
351356
test_cmp actual expect
352357
'

t/t3200-branch.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ test_expect_success 'git branch HEAD should fail' '
7676
'
7777

7878
cat >expect <<EOF
79-
$ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
79+
$HEAD refs/heads/d/e/f@{0}: branch: Created from main
8080
EOF
8181
test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
8282
GIT_COMMITTER_DATE="2005-05-26 23:30" \
8383
git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
8484
test_ref_exists refs/heads/d/e/f &&
85-
test_path_is_file .git/logs/refs/heads/d/e/f &&
86-
test_cmp expect .git/logs/refs/heads/d/e/f
85+
git reflog show --no-abbrev-commit refs/heads/d/e/f >actual &&
86+
test_cmp expect actual
8787
'
8888

8989
test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
@@ -203,10 +203,9 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou
203203
test $(git rev-parse --abbrev-ref HEAD) = bam
204204
'
205205

206-
test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
207-
msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
208-
grep " $ZERO_OID.*$msg$" .git/logs/HEAD &&
209-
grep "^$ZERO_OID.*$msg$" .git/logs/HEAD
206+
test_expect_success 'git branch -M baz bam should add entries to HEAD reflog' '
207+
git reflog show HEAD >actual &&
208+
grep "HEAD@{0}: Branch: renamed refs/heads/baz to refs/heads/bam" actual
210209
'
211210

212211
test_expect_success 'git branch -M should leave orphaned HEAD alone' '
@@ -228,7 +227,7 @@ test_expect_success 'git branch -M should leave orphaned HEAD alone' '
228227
test_expect_success 'resulting reflog can be shown by log -g' '
229228
oid=$(git rev-parse HEAD) &&
230229
cat >expect <<-EOF &&
231-
HEAD@{0} $oid $msg
230+
HEAD@{0} $oid Branch: renamed refs/heads/baz to refs/heads/bam
232231
HEAD@{2} $oid checkout: moving from foo to baz
233232
EOF
234233
git log -g --format="%gd %H %gs" -2 HEAD >actual &&
@@ -702,7 +701,8 @@ test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out'
702701

703702
test_expect_success 'git branch -C c1 c2 should never touch HEAD' '
704703
msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
705-
! grep "$msg$" .git/logs/HEAD
704+
git reflog HEAD >actual &&
705+
! grep "$msg$" actual
706706
'
707707

708708
test_expect_success 'git branch -C main should work when main is checked out' '
@@ -1143,14 +1143,14 @@ test_expect_success '--set-upstream-to notices an error to set branch as own ups
11431143

11441144
# Keep this test last, as it changes the current branch
11451145
cat >expect <<EOF
1146-
$ZERO_OID $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from main
1146+
$HEAD refs/heads/g/h/i@{0}: branch: Created from main
11471147
EOF
11481148
test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
11491149
GIT_COMMITTER_DATE="2005-05-26 23:30" \
11501150
git checkout -b g/h/i -l main &&
11511151
test_ref_exists refs/heads/g/h/i &&
1152-
test_path_is_file .git/logs/refs/heads/g/h/i &&
1153-
test_cmp expect .git/logs/refs/heads/g/h/i
1152+
git reflog show --no-abbrev-commit refs/heads/g/h/i >actual &&
1153+
test_cmp expect actual
11541154
'
11551155

11561156
test_expect_success 'checkout -b makes reflog by default' '

0 commit comments

Comments
 (0)