Skip to content

Commit 0300f95

Browse files
committed
Merge branch 'ps/ref-tests-update' into seen
* ps/ref-tests-update: t: mark several tests that assume the files backend with REFFILES t7900: assert the absence of refs via git-for-each-ref(1) t7300: assert exact states of repo t4207: delete replace references via git-update-ref(1) t1450: convert tests to remove worktrees via git-worktree(1) t: convert tests to not access reflog via the filesystem t: convert tests to not access symrefs via the filesystem t: convert tests to not write references via the filesystem t: allow skipping expected object ID in `ref-store update-ref`
2 parents 65c6235 + 7f409e1 commit 0300f95

17 files changed

+142
-108
lines changed

t/helper/test-ref-store.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,19 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
298298
const char *new_sha1_buf = notnull(*argv++, "new-sha1");
299299
const char *old_sha1_buf = notnull(*argv++, "old-sha1");
300300
unsigned int flags = arg_flags(*argv++, "flags", transaction_flags);
301-
struct object_id old_oid;
301+
struct object_id old_oid, *old_oid_ptr = NULL;
302302
struct object_id new_oid;
303303

304-
if (get_oid_hex(old_sha1_buf, &old_oid))
305-
die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name);
304+
if (*old_sha1_buf) {
305+
if (get_oid_hex(old_sha1_buf, &old_oid))
306+
die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name);
307+
old_oid_ptr = &old_oid;
308+
}
306309
if (get_oid_hex(new_sha1_buf, &new_oid))
307310
die("cannot parse %s as %s", new_sha1_buf, the_hash_algo->name);
308311

309312
return refs_update_ref(refs, msg, refname,
310-
&new_oid, &old_oid,
313+
&new_oid, old_oid_ptr,
311314
flags, UPDATE_REFS_DIE_ON_ERR);
312315
}
313316

t/t1400-update-ref.sh

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ test_description='Test git update-ref and basic ref logging'
99
Z=$ZERO_OID
1010

1111
m=refs/heads/main
12-
n_dir=refs/heads/gu
13-
n=$n_dir/fixes
1412
outside=refs/foo
1513
bare=bare-repo
1614

@@ -62,10 +60,10 @@ test_expect_success "delete $m without oldvalue verification" '
6260
test_must_fail git show-ref --verify -q $m
6361
'
6462

65-
test_expect_success "fail to create $n" '
66-
test_when_finished "rm -f .git/$n_dir" &&
67-
touch .git/$n_dir &&
68-
test_must_fail git update-ref $n $A
63+
test_expect_success "fail to create $n due to file/directory conflict" '
64+
test_when_finished "git update-ref -d refs/heads/gu" &&
65+
git update-ref refs/heads/gu $A &&
66+
test_must_fail git update-ref refs/heads/gu/fixes $A
6967
'
7068

7169
test_expect_success "create $m (by HEAD)" '
@@ -92,7 +90,8 @@ test_expect_success "deleting current branch adds message to HEAD's log" '
9290
git symbolic-ref HEAD $m &&
9391
git update-ref -m delete-$m -d $m &&
9492
test_must_fail git show-ref --verify -q $m &&
95-
grep "delete-$m$" .git/logs/HEAD
93+
test-tool ref-store main for-each-reflog-ent HEAD >actual &&
94+
grep "delete-$m$" actual
9695
'
9796

9897
test_expect_success "deleting by HEAD adds message to HEAD's log" '
@@ -101,7 +100,8 @@ test_expect_success "deleting by HEAD adds message to HEAD's log" '
101100
git symbolic-ref HEAD $m &&
102101
git update-ref -m delete-by-head -d HEAD &&
103102
test_must_fail git show-ref --verify -q $m &&
104-
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
105105
'
106106

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

133133
test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
134134
test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
135-
rm $bare/logs/$m" &&
135+
test-tool ref-store main delete-reflog $m" &&
136136
git -C $bare config core.logAllRefUpdates true &&
137137
git -C $bare update-ref $m $bareB &&
138138
git -C $bare rev-parse $bareB >expect &&
@@ -221,27 +221,27 @@ test_expect_success 'delete symref without dereference when the referred ref is
221221
'
222222

223223
test_expect_success 'update-ref -d is not confused by self-reference' '
224+
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
224225
git symbolic-ref refs/heads/self refs/heads/self &&
225-
test_when_finished "rm -f .git/refs/heads/self" &&
226-
test_path_is_file .git/refs/heads/self &&
226+
git symbolic-ref --no-recurse refs/heads/self &&
227227
test_must_fail git update-ref -d refs/heads/self &&
228-
test_path_is_file .git/refs/heads/self
228+
git symbolic-ref --no-recurse refs/heads/self
229229
'
230230

231231
test_expect_success 'update-ref --no-deref -d can delete self-reference' '
232+
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
232233
git symbolic-ref refs/heads/self refs/heads/self &&
233-
test_when_finished "rm -f .git/refs/heads/self" &&
234-
test_path_is_file .git/refs/heads/self &&
234+
git symbolic-ref --no-recurse refs/heads/self &&
235235
git update-ref --no-deref -d refs/heads/self &&
236236
test_must_fail git show-ref --verify -q refs/heads/self
237237
'
238238

239-
test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239+
test_expect_success REFFILES 'update-ref --no-deref -d can delete reference to bad ref' '
240240
>.git/refs/heads/bad &&
241241
test_when_finished "rm -f .git/refs/heads/bad" &&
242242
git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
243243
test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
244-
test_path_is_file .git/refs/heads/ref-to-bad &&
244+
git symbolic-ref --no-recurse refs/heads/ref-to-bad &&
245245
git update-ref --no-deref -d refs/heads/ref-to-bad &&
246246
test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
247247
'
@@ -265,7 +265,10 @@ test_expect_success "(not) changed .git/$m" '
265265
! test $B = $(git show-ref -s --verify $m)
266266
'
267267

268-
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+
269272
test_expect_success "create $m (logged by touch)" '
270273
test_config core.logAllRefUpdates false &&
271274
GIT_COMMITTER_DATE="2005-05-26 23:30" \
@@ -285,7 +288,7 @@ test_expect_success "set $m (logged by touch)" '
285288
test $A = $(git show-ref -s --verify $m)
286289
'
287290

288-
test_expect_success 'empty directory removal' '
291+
test_expect_success REFFILES 'empty directory removal' '
289292
git branch d1/d2/r1 HEAD &&
290293
git branch d1/r2 HEAD &&
291294
test_path_is_file .git/refs/heads/d1/d2/r1 &&
@@ -297,7 +300,7 @@ test_expect_success 'empty directory removal' '
297300
test_path_is_file .git/logs/refs/heads/d1/r2
298301
'
299302

300-
test_expect_success 'symref empty directory removal' '
303+
test_expect_success REFFILES 'symref empty directory removal' '
301304
git branch e1/e2/r1 HEAD &&
302305
git branch e1/r2 HEAD &&
303306
git checkout e1/e2/r1 &&
@@ -318,7 +321,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
318321
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
319322
EOF
320323
test_expect_success "verifying $m's log (logged by touch)" '
321-
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" &&
322325
test-tool ref-store main for-each-reflog-ent $m >actual &&
323326
test_cmp actual expect
324327
'
@@ -348,7 +351,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
348351
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
349352
EOF
350353
test_expect_success "verifying $m's log (logged by config)" '
351-
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" &&
352355
test-tool ref-store main for-each-reflog-ent $m >actual &&
353356
test_cmp actual expect
354357
'
@@ -434,7 +437,8 @@ test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
434437
test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
435438
'
436439

437-
rm -f .git/$m .git/logs/$m expect
440+
rm -f expect
441+
git update-ref -d $m
438442

439443
test_expect_success 'creating initial files' '
440444
test_when_finished rm -f M &&
@@ -1635,7 +1639,7 @@ test_expect_success PIPE 'transaction flushes status updates' '
16351639
test_cmp expected actual
16361640
'
16371641

1638-
test_expect_success 'directory not created deleting packed ref' '
1642+
test_expect_success REFFILES 'directory not created deleting packed ref' '
16391643
git branch d1/d2/r1 HEAD &&
16401644
git pack-refs --all &&
16411645
test_path_is_missing .git/refs/heads/d1/d2 &&

t/t1430-bad-ref-name.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ test_expect_success 'rev-parse skips symref pointing to broken name' '
164164
test_expect_success 'for-each-ref emits warnings for broken names' '
165165
test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
166166
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" &&
167-
printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
167+
test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref &&
168168
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
169-
printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
169+
test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
170170
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
171171
git for-each-ref >output 2>error &&
172172
! grep -e "broken\.\.\.ref" output &&
@@ -252,7 +252,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' '
252252
'
253253

254254
test_expect_success 'update-ref --no-deref -d can delete symref with broken name' '
255-
printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
255+
test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
256256
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
257257
git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
258258
test_path_is_missing .git/refs/heads/broken...symref &&
@@ -261,7 +261,7 @@ test_expect_success 'update-ref --no-deref -d can delete symref with broken name
261261
'
262262

263263
test_expect_success 'branch -d can delete symref with broken name' '
264-
printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
264+
test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
265265
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
266266
git branch -d broken...symref >output 2>error &&
267267
test_path_is_missing .git/refs/heads/broken...symref &&
@@ -270,7 +270,7 @@ test_expect_success 'branch -d can delete symref with broken name' '
270270
'
271271

272272
test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' '
273-
printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
273+
test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist &&
274274
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
275275
git update-ref --no-deref -d refs/heads/broken...symref >output 2>error &&
276276
test_path_is_missing .git/refs/heads/broken...symref &&
@@ -279,7 +279,7 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref with br
279279
'
280280

281281
test_expect_success 'branch -d can delete dangling symref with broken name' '
282-
printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
282+
test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist &&
283283
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
284284
git branch -d broken...symref >output 2>error &&
285285
test_path_is_missing .git/refs/heads/broken...symref &&

t/t1450-fsck.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test_expect_success setup '
1515
git config --unset i18n.commitencoding &&
1616
git checkout HEAD^0 &&
1717
test_commit B fileB two &&
18+
orig_head=$(git rev-parse HEAD) &&
1819
git tag -d A B &&
1920
git reflog expire --expire=now --all
2021
'
@@ -115,61 +116,60 @@ test_expect_success 'zlib corrupt loose object output ' '
115116
'
116117

117118
test_expect_success 'branch pointing to non-commit' '
118-
git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
119+
tree_oid=$(git rev-parse --verify HEAD^{tree}) &&
119120
test_when_finished "git update-ref -d refs/heads/invalid" &&
121+
test-tool ref-store main update-ref msg refs/heads/invalid $tree_oid $ZERO_OID REF_SKIP_OID_VERIFICATION &&
120122
test_must_fail git fsck 2>out &&
121123
test_i18ngrep "not a commit" out
122124
'
123125

124-
test_expect_success 'HEAD link pointing at a funny object' '
125-
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
126-
mv .git/HEAD .git/SAVED_HEAD &&
126+
test_expect_success REFFILES 'HEAD link pointing at a funny object' '
127+
test_when_finished "git update-ref HEAD $orig_head" &&
127128
echo $ZERO_OID >.git/HEAD &&
128129
# avoid corrupt/broken HEAD from interfering with repo discovery
129130
test_must_fail env GIT_DIR=.git git fsck 2>out &&
130131
test_i18ngrep "detached HEAD points" out
131132
'
132133

133134
test_expect_success 'HEAD link pointing at a funny place' '
134-
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
135-
mv .git/HEAD .git/SAVED_HEAD &&
136-
echo "ref: refs/funny/place" >.git/HEAD &&
135+
test_when_finished "git update-ref --no-deref HEAD $orig_head" &&
136+
test-tool ref-store main create-symref HEAD refs/funny/place &&
137137
# avoid corrupt/broken HEAD from interfering with repo discovery
138138
test_must_fail env GIT_DIR=.git git fsck 2>out &&
139139
test_i18ngrep "HEAD points to something strange" out
140140
'
141141

142-
test_expect_success 'HEAD link pointing at a funny object (from different wt)' '
143-
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
144-
test_when_finished "rm -rf .git/worktrees wt" &&
142+
test_expect_success REFFILES 'HEAD link pointing at a funny object (from different wt)' '
143+
test_when_finished "git update-ref HEAD $orig_head" &&
144+
test_when_finished "git worktree remove -f wt" &&
145145
git worktree add wt &&
146-
mv .git/HEAD .git/SAVED_HEAD &&
147146
echo $ZERO_OID >.git/HEAD &&
148147
# avoid corrupt/broken HEAD from interfering with repo discovery
149148
test_must_fail git -C wt fsck 2>out &&
150149
test_i18ngrep "main-worktree/HEAD: detached HEAD points" out
151150
'
152151

153-
test_expect_success 'other worktree HEAD link pointing at a funny object' '
154-
test_when_finished "rm -rf .git/worktrees other" &&
152+
test_expect_success REFFILES 'other worktree HEAD link pointing at a funny object' '
153+
test_when_finished "git worktree remove -f other" &&
155154
git worktree add other &&
156155
echo $ZERO_OID >.git/worktrees/other/HEAD &&
157156
test_must_fail git fsck 2>out &&
158157
test_i18ngrep "worktrees/other/HEAD: detached HEAD points" out
159158
'
160159

161160
test_expect_success 'other worktree HEAD link pointing at missing object' '
162-
test_when_finished "rm -rf .git/worktrees other" &&
161+
test_when_finished "git worktree remove -f other" &&
163162
git worktree add other &&
164-
echo "Contents missing from repo" | git hash-object --stdin >.git/worktrees/other/HEAD &&
163+
object_id=$(echo "Contents missing from repo" | git hash-object --stdin) &&
164+
test-tool -C other ref-store main update-ref msg HEAD $object_id "" REF_NO_DEREF,REF_SKIP_OID_VERIFICATION &&
165165
test_must_fail git fsck 2>out &&
166166
test_i18ngrep "worktrees/other/HEAD: invalid sha1 pointer" out
167167
'
168168

169169
test_expect_success 'other worktree HEAD link pointing at a funny place' '
170-
test_when_finished "rm -rf .git/worktrees other" &&
170+
test_when_finished "git worktree remove -f other" &&
171171
git worktree add other &&
172-
echo "ref: refs/funny/place" >.git/worktrees/other/HEAD &&
172+
git -C other symbolic-ref HEAD refs/funny/place &&
173173
test_must_fail git fsck 2>out &&
174174
test_i18ngrep "worktrees/other/HEAD points to something strange" out
175175
'
@@ -391,7 +391,7 @@ test_expect_success 'tag pointing to nonexistent' '
391391
392392
tag=$(git hash-object -t tag -w --stdin <invalid-tag) &&
393393
test_when_finished "remove_object $tag" &&
394-
echo $tag >.git/refs/tags/invalid &&
394+
git update-ref refs/tags/invalid $tag &&
395395
test_when_finished "git update-ref -d refs/tags/invalid" &&
396396
test_must_fail git fsck --tags >out &&
397397
test_i18ngrep "broken link" out
@@ -411,7 +411,7 @@ test_expect_success 'tag pointing to something else than its type' '
411411
412412
tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
413413
test_when_finished "remove_object $tag" &&
414-
echo $tag >.git/refs/tags/wrong &&
414+
git update-ref refs/tags/wrong $tag &&
415415
test_when_finished "git update-ref -d refs/tags/wrong" &&
416416
test_must_fail git fsck --tags
417417
'
@@ -428,7 +428,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
428428
429429
tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
430430
test_when_finished "remove_object $tag" &&
431-
echo $tag >.git/refs/tags/wrong &&
431+
git update-ref refs/tags/wrong $tag &&
432432
test_when_finished "git update-ref -d refs/tags/wrong" &&
433433
git fsck --tags 2>out &&
434434
@@ -452,7 +452,7 @@ test_expect_success 'tag with bad tagger' '
452452
453453
tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
454454
test_when_finished "remove_object $tag" &&
455-
echo $tag >.git/refs/tags/wrong &&
455+
git update-ref refs/tags/wrong $tag &&
456456
test_when_finished "git update-ref -d refs/tags/wrong" &&
457457
test_must_fail git fsck --tags 2>out &&
458458
test_i18ngrep "error in tag .*: invalid author/committer" out
@@ -471,7 +471,7 @@ test_expect_success 'tag with NUL in header' '
471471
472472
tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) &&
473473
test_when_finished "remove_object $tag" &&
474-
echo $tag >.git/refs/tags/wrong &&
474+
git update-ref refs/tags/wrong $tag &&
475475
test_when_finished "git update-ref -d refs/tags/wrong" &&
476476
test_must_fail git fsck --tags 2>out &&
477477
test_i18ngrep "error in tag $tag.*unterminated header: NUL at offset" out

0 commit comments

Comments
 (0)