Skip to content

Commit c9780bb

Browse files
committed
Merge branch 'hn/prep-tests-for-reftable'
Preliminary clean-up of tests before the main reftable changes hits the codebase. * hn/prep-tests-for-reftable: (22 commits) t1415: set REFFILES for test specific to storage format t4202: mark bogus head hash test with REFFILES t7003: check reflog existence only for REFFILES t7900: stop checking for loose refs t1404: mark tests that muck with .git directly as REFFILES. t2017: mark --orphan/logAllRefUpdates=false test as REFFILES t1414: mark corruption test with REFFILES t1407: require REFFILES for for_each_reflog test test-lib: provide test prereq REFFILES t5304: use "reflog expire --all" to clear the reflog t5304: restyle: trim empty lines, drop ':' before > t7003: use rev-parse rather than FS inspection t5000: inspect HEAD using git-rev-parse t5000: reformat indentation to the latest fashion t1301: fix typo in error message t1413: use tar to save and restore entire .git directory t1401-symbolic-ref: avoid direct filesystem access t1401: use tar to snapshot and restore repo state t5601: read HEAD using rev-parse t9300: check ref existence using test-helper rather than a file system check ...
2 parents 0659866 + 1231cab commit c9780bb

18 files changed

+170
-159
lines changed

t/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,12 @@ use these, and "test_set_prereq" for how to define your own.
11261126

11271127
Git wasn't compiled with NO_PTHREADS=YesPlease.
11281128

1129+
- REFFILES
1130+
1131+
Test is specific to packed/loose ref storage, and should be
1132+
disabled for other ref storage backends
1133+
1134+
11291135
Tips for Writing Tests
11301136
----------------------
11311137

t/helper/test-ref-store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
118118

119119
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
120120
{
121-
struct object_id oid;
121+
struct object_id oid = *null_oid();
122122
const char *refname = notnull(*argv++, "refname");
123123
int resolve_flags = arg_flags(*argv++, "resolve-flags");
124124
int flags;

t/t1301-shared-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
124124
: happy
125125
;;
126126
*)
127-
echo Ooops, .git/logs/refs/heads/main is not 0662 [$actual]
127+
echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
128128
false
129129
;;
130130
esac

t/t1401-symbolic-ref.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,33 @@ test_description='basic symbolic-ref tests'
77
# the git repo, meaning that further tests will operate on
88
# the surrounding git repo instead of the trash directory.
99
reset_to_sane() {
10-
echo ref: refs/heads/foo >.git/HEAD
10+
rm -rf .git &&
11+
"$TAR" xf .git.tar
1112
}
1213

13-
test_expect_success 'symbolic-ref writes HEAD' '
14+
test_expect_success 'setup' '
1415
git symbolic-ref HEAD refs/heads/foo &&
15-
echo ref: refs/heads/foo >expect &&
16-
test_cmp expect .git/HEAD
16+
test_commit file &&
17+
"$TAR" cf .git.tar .git/
1718
'
1819

19-
test_expect_success 'symbolic-ref reads HEAD' '
20-
echo refs/heads/foo >expect &&
20+
test_expect_success 'symbolic-ref read/write roundtrip' '
21+
git symbolic-ref HEAD refs/heads/read-write-roundtrip &&
22+
echo refs/heads/read-write-roundtrip >expect &&
2123
git symbolic-ref HEAD >actual &&
2224
test_cmp expect actual
2325
'
2426

2527
test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
2628
test_must_fail git symbolic-ref HEAD foo
2729
'
30+
2831
reset_to_sane
2932

3033
test_expect_success 'symbolic-ref refuses bare sha1' '
31-
echo content >file && git add file && git commit -m one &&
3234
test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
3335
'
36+
3437
reset_to_sane
3538

3639
test_expect_success 'HEAD cannot be removed' '
@@ -42,16 +45,16 @@ reset_to_sane
4245
test_expect_success 'symbolic-ref can be deleted' '
4346
git symbolic-ref NOTHEAD refs/heads/foo &&
4447
git symbolic-ref -d NOTHEAD &&
45-
test_path_is_file .git/refs/heads/foo &&
46-
test_path_is_missing .git/NOTHEAD
48+
git rev-parse refs/heads/foo &&
49+
test_must_fail git symbolic-ref NOTHEAD
4750
'
4851
reset_to_sane
4952

5053
test_expect_success 'symbolic-ref can delete dangling symref' '
5154
git symbolic-ref NOTHEAD refs/heads/missing &&
5255
git symbolic-ref -d NOTHEAD &&
53-
test_path_is_missing .git/refs/heads/missing &&
54-
test_path_is_missing .git/NOTHEAD
56+
test_must_fail git rev-parse refs/heads/missing &&
57+
test_must_fail git symbolic-ref NOTHEAD
5558
'
5659
reset_to_sane
5760

t/t1404-update-ref-errors.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test_expect_success 'one new ref is a simple prefix of another' '
189189
190190
'
191191

192-
test_expect_success 'empty directory should not fool rev-parse' '
192+
test_expect_success REFFILES 'empty directory should not fool rev-parse' '
193193
prefix=refs/e-rev-parse &&
194194
git update-ref $prefix/foo $C &&
195195
git pack-refs --all &&
@@ -199,7 +199,7 @@ test_expect_success 'empty directory should not fool rev-parse' '
199199
test_cmp expected actual
200200
'
201201

202-
test_expect_success 'empty directory should not fool for-each-ref' '
202+
test_expect_success REFFILES 'empty directory should not fool for-each-ref' '
203203
prefix=refs/e-for-each-ref &&
204204
git update-ref $prefix/foo $C &&
205205
git for-each-ref $prefix >expected &&
@@ -209,14 +209,14 @@ test_expect_success 'empty directory should not fool for-each-ref' '
209209
test_cmp expected actual
210210
'
211211

212-
test_expect_success 'empty directory should not fool create' '
212+
test_expect_success REFFILES 'empty directory should not fool create' '
213213
prefix=refs/e-create &&
214214
mkdir -p .git/$prefix/foo/bar/baz &&
215215
printf "create %s $C\n" $prefix/foo |
216216
git update-ref --stdin
217217
'
218218

219-
test_expect_success 'empty directory should not fool verify' '
219+
test_expect_success REFFILES 'empty directory should not fool verify' '
220220
prefix=refs/e-verify &&
221221
git update-ref $prefix/foo $C &&
222222
git pack-refs --all &&
@@ -225,7 +225,7 @@ test_expect_success 'empty directory should not fool verify' '
225225
git update-ref --stdin
226226
'
227227

228-
test_expect_success 'empty directory should not fool 1-arg update' '
228+
test_expect_success REFFILES 'empty directory should not fool 1-arg update' '
229229
prefix=refs/e-update-1 &&
230230
git update-ref $prefix/foo $C &&
231231
git pack-refs --all &&
@@ -234,7 +234,7 @@ test_expect_success 'empty directory should not fool 1-arg update' '
234234
git update-ref --stdin
235235
'
236236

237-
test_expect_success 'empty directory should not fool 2-arg update' '
237+
test_expect_success REFFILES 'empty directory should not fool 2-arg update' '
238238
prefix=refs/e-update-2 &&
239239
git update-ref $prefix/foo $C &&
240240
git pack-refs --all &&
@@ -243,7 +243,7 @@ test_expect_success 'empty directory should not fool 2-arg update' '
243243
git update-ref --stdin
244244
'
245245

246-
test_expect_success 'empty directory should not fool 0-arg delete' '
246+
test_expect_success REFFILES 'empty directory should not fool 0-arg delete' '
247247
prefix=refs/e-delete-0 &&
248248
git update-ref $prefix/foo $C &&
249249
git pack-refs --all &&
@@ -252,7 +252,7 @@ test_expect_success 'empty directory should not fool 0-arg delete' '
252252
git update-ref --stdin
253253
'
254254

255-
test_expect_success 'empty directory should not fool 1-arg delete' '
255+
test_expect_success REFFILES 'empty directory should not fool 1-arg delete' '
256256
prefix=refs/e-delete-1 &&
257257
git update-ref $prefix/foo $C &&
258258
git pack-refs --all &&
@@ -466,7 +466,7 @@ test_expect_success 'incorrect old value blocks indirect no-deref delete' '
466466
test_cmp expected output.err
467467
'
468468

469-
test_expect_success 'non-empty directory blocks create' '
469+
test_expect_success REFFILES 'non-empty directory blocks create' '
470470
prefix=refs/ne-create &&
471471
mkdir -p .git/$prefix/foo/bar &&
472472
: >.git/$prefix/foo/bar/baz.lock &&
@@ -485,7 +485,7 @@ test_expect_success 'non-empty directory blocks create' '
485485
test_cmp expected output.err
486486
'
487487

488-
test_expect_success 'broken reference blocks create' '
488+
test_expect_success REFFILES 'broken reference blocks create' '
489489
prefix=refs/broken-create &&
490490
mkdir -p .git/$prefix &&
491491
echo "gobbledigook" >.git/$prefix/foo &&
@@ -504,7 +504,7 @@ test_expect_success 'broken reference blocks create' '
504504
test_cmp expected output.err
505505
'
506506

507-
test_expect_success 'non-empty directory blocks indirect create' '
507+
test_expect_success REFFILES 'non-empty directory blocks indirect create' '
508508
prefix=refs/ne-indirect-create &&
509509
git symbolic-ref $prefix/symref $prefix/foo &&
510510
mkdir -p .git/$prefix/foo/bar &&
@@ -524,7 +524,7 @@ test_expect_success 'non-empty directory blocks indirect create' '
524524
test_cmp expected output.err
525525
'
526526

527-
test_expect_success 'broken reference blocks indirect create' '
527+
test_expect_success REFFILES 'broken reference blocks indirect create' '
528528
prefix=refs/broken-indirect-create &&
529529
git symbolic-ref $prefix/symref $prefix/foo &&
530530
echo "gobbledigook" >.git/$prefix/foo &&
@@ -543,7 +543,7 @@ test_expect_success 'broken reference blocks indirect create' '
543543
test_cmp expected output.err
544544
'
545545

546-
test_expect_success 'no bogus intermediate values during delete' '
546+
test_expect_success REFFILES 'no bogus intermediate values during delete' '
547547
prefix=refs/slow-transaction &&
548548
# Set up a reference with differing loose and packed versions:
549549
git update-ref $prefix/foo $C &&
@@ -600,7 +600,7 @@ test_expect_success 'no bogus intermediate values during delete' '
600600
test_must_fail git rev-parse --verify --quiet $prefix/foo
601601
'
602602

603-
test_expect_success 'delete fails cleanly if packed-refs file is locked' '
603+
test_expect_success REFFILES 'delete fails cleanly if packed-refs file is locked' '
604604
prefix=refs/locked-packed-refs &&
605605
# Set up a reference with differing loose and packed versions:
606606
git update-ref $prefix/foo $C &&
@@ -616,7 +616,7 @@ test_expect_success 'delete fails cleanly if packed-refs file is locked' '
616616
test_cmp unchanged actual
617617
'
618618

619-
test_expect_success 'delete fails cleanly if packed-refs.new write fails' '
619+
test_expect_success REFFILES 'delete fails cleanly if packed-refs.new write fails' '
620620
# Setup and expectations are similar to the test above.
621621
prefix=refs/failed-packed-refs &&
622622
git update-ref $prefix/foo $C &&

t/t1407-worktree-ref-store.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ test_expect_success 'create_symref(FOO, refs/heads/main)' '
5252
test_cmp expected actual
5353
'
5454

55-
test_expect_success 'for_each_reflog()' '
55+
# Some refs (refs/bisect/*, pseudorefs) are kept per worktree, so they should
56+
# only appear in the for-each-reflog output if it is called from the correct
57+
# worktree, which is exercised in this test. This test is poorly written (and
58+
# therefore marked REFFILES) for mulitple reasons: 1) it creates invalidly
59+
# formatted log entres. 2) it uses direct FS access for creating the reflogs. 3)
60+
# PSEUDO-WT and refs/bisect/random do not create reflogs by default, so it is
61+
# not testing a realistic scenario.
62+
test_expect_success REFFILES 'for_each_reflog()' '
5663
echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
5764
mkdir -p .git/logs/refs/bisect &&
5865
echo $ZERO_OID > .git/logs/refs/bisect/random &&

t/t1413-reflog-detach.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77
. ./test-lib.sh
88

99
reset_state () {
10-
git checkout main &&
11-
cp saved_reflog .git/logs/HEAD
10+
rm -rf .git && "$TAR" xf .git-saved.tar
1211
}
1312

1413
test_expect_success setup '
@@ -17,7 +16,7 @@ test_expect_success setup '
1716
git branch side &&
1817
test_tick &&
1918
git commit --allow-empty -m second &&
20-
cat .git/logs/HEAD >saved_reflog
19+
"$TAR" cf .git-saved.tar .git
2120
'
2221

2322
test_expect_success baseline '

t/t1414-reflog-walk.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ test_expect_success 'min/max age uses entry date to limit' '
119119
test_cmp expect actual
120120
'
121121

122-
test_expect_success 'walk prefers reflog to ref tip' '
122+
# Create a situation where the reflog and ref database disagree about the latest
123+
# state of HEAD.
124+
test_expect_success REFFILES 'walk prefers reflog to ref tip' '
123125
head=$(git rev-parse HEAD) &&
124126
one=$(git rev-parse one) &&
125127
ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&

t/t1415-worktree-refs.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ test_expect_success 'setup' '
1616
git -C wt2 update-ref refs/worktree/foo HEAD
1717
'
1818

19-
test_expect_success 'refs/worktree must not be packed' '
19+
# The 'packed-refs' file is stored directly in .git/. This means it is global
20+
# to the repository, and can only contain refs that are shared across all
21+
# worktrees.
22+
test_expect_success REFFILES 'refs/worktree must not be packed' '
2023
git pack-refs --all &&
2124
test_path_is_missing .git/refs/tags/wt1 &&
2225
test_path_is_file .git/refs/worktree/foo &&

t/t2017-checkout-orphan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test_expect_success '--orphan makes reflog by default' '
7676
git rev-parse --verify delta@{0}
7777
'
7878

79-
test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' '
79+
test_expect_success REFFILES '--orphan does not make reflog when core.logAllRefUpdates = false' '
8080
git checkout main &&
8181
git config core.logAllRefUpdates false &&
8282
git checkout --orphan epsilon &&

t/t4202-log.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,14 +1834,24 @@ test_expect_success 'log --graph --no-walk is forbidden' '
18341834
test_must_fail git log --graph --no-walk
18351835
'
18361836

1837-
test_expect_success 'log diagnoses bogus HEAD' '
1837+
test_expect_success 'log on empty repo fails' '
18381838
git init empty &&
1839+
test_when_finished "rm -rf empty" &&
18391840
test_must_fail git -C empty log 2>stderr &&
1840-
test_i18ngrep does.not.have.any.commits stderr &&
1841+
test_i18ngrep does.not.have.any.commits stderr
1842+
'
1843+
1844+
test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
1845+
git init empty &&
1846+
test_when_finished "rm -rf empty" &&
18411847
echo 1234abcd >empty/.git/refs/heads/main &&
18421848
test_must_fail git -C empty log 2>stderr &&
1843-
test_i18ngrep broken stderr &&
1844-
echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD &&
1849+
test_i18ngrep broken stderr
1850+
'
1851+
1852+
test_expect_success 'log diagnoses bogus HEAD symref' '
1853+
git init empty &&
1854+
git --git-dir empty/.git symbolic-ref HEAD refs/heads/invalid.lock &&
18451855
test_must_fail git -C empty log 2>stderr &&
18461856
test_i18ngrep broken stderr &&
18471857
test_must_fail git -C empty log --default totally-bogus 2>stderr &&

0 commit comments

Comments
 (0)