@@ -15,6 +15,7 @@ test_expect_success setup '
15
15
git config --unset i18n.commitencoding &&
16
16
git checkout HEAD^0 &&
17
17
test_commit B fileB two &&
18
+ orig_head=$(git rev-parse HEAD) &&
18
19
git tag -d A B &&
19
20
git reflog expire --expire=now --all
20
21
'
@@ -115,35 +116,33 @@ test_expect_success 'zlib corrupt loose object output ' '
115
116
'
116
117
117
118
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}) &&
119
120
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 &&
120
122
test_must_fail git fsck 2>out &&
121
123
test_i18ngrep "not a commit" out
122
124
'
123
125
124
126
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 &&
127
+ test_when_finished "git update-ref HEAD $orig_head" &&
127
128
echo $ZERO_OID >.git/HEAD &&
128
129
# avoid corrupt/broken HEAD from interfering with repo discovery
129
130
test_must_fail env GIT_DIR=.git git fsck 2>out &&
130
131
test_i18ngrep "detached HEAD points" out
131
132
'
132
133
133
134
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 &&
135
+ test_when_finished "git update-ref --no-deref HEAD $orig_head" &&
136
136
echo "ref: refs/funny/place" >.git/HEAD &&
137
137
# avoid corrupt/broken HEAD from interfering with repo discovery
138
138
test_must_fail env GIT_DIR=.git git fsck 2>out &&
139
139
test_i18ngrep "HEAD points to something strange" out
140
140
'
141
141
142
142
test_expect_success ' HEAD link pointing at a funny object (from different wt)' '
143
- test_when_finished "mv . git/SAVED_HEAD .git/ HEAD" &&
143
+ test_when_finished "git update-ref HEAD $orig_head " &&
144
144
test_when_finished "rm -rf .git/worktrees wt" &&
145
145
git worktree add wt &&
146
- mv .git/HEAD .git/SAVED_HEAD &&
147
146
echo $ZERO_OID >.git/HEAD &&
148
147
# avoid corrupt/broken HEAD from interfering with repo discovery
149
148
test_must_fail git -C wt fsck 2>out &&
@@ -161,7 +160,8 @@ test_expect_success 'other worktree HEAD link pointing at a funny object' '
161
160
test_expect_success ' other worktree HEAD link pointing at missing object' '
162
161
test_when_finished "rm -rf .git/worktrees other" &&
163
162
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 &&
165
165
test_must_fail git fsck 2>out &&
166
166
test_i18ngrep "worktrees/other/HEAD: invalid sha1 pointer" out
167
167
'
@@ -391,7 +391,7 @@ test_expect_success 'tag pointing to nonexistent' '
391
391
392
392
tag=$(git hash-object -t tag -w --stdin <invalid-tag) &&
393
393
test_when_finished "remove_object $tag" &&
394
- echo $tag >.git/ refs/tags/invalid &&
394
+ git update-ref refs/tags/invalid $tag &&
395
395
test_when_finished "git update-ref -d refs/tags/invalid" &&
396
396
test_must_fail git fsck --tags >out &&
397
397
test_i18ngrep "broken link" out
@@ -411,7 +411,7 @@ test_expect_success 'tag pointing to something else than its type' '
411
411
412
412
tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
413
413
test_when_finished "remove_object $tag" &&
414
- echo $tag >.git/ refs/tags/wrong &&
414
+ git update-ref refs/tags/wrong $tag &&
415
415
test_when_finished "git update-ref -d refs/tags/wrong" &&
416
416
test_must_fail git fsck --tags
417
417
'
@@ -428,7 +428,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
428
428
429
429
tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
430
430
test_when_finished "remove_object $tag" &&
431
- echo $tag >.git/ refs/tags/wrong &&
431
+ git update-ref refs/tags/wrong $tag &&
432
432
test_when_finished "git update-ref -d refs/tags/wrong" &&
433
433
git fsck --tags 2>out &&
434
434
@@ -452,7 +452,7 @@ test_expect_success 'tag with bad tagger' '
452
452
453
453
tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
454
454
test_when_finished "remove_object $tag" &&
455
- echo $tag >.git/ refs/tags/wrong &&
455
+ git update-ref refs/tags/wrong $tag &&
456
456
test_when_finished "git update-ref -d refs/tags/wrong" &&
457
457
test_must_fail git fsck --tags 2>out &&
458
458
test_i18ngrep "error in tag .*: invalid author/committer" out
@@ -471,7 +471,7 @@ test_expect_success 'tag with NUL in header' '
471
471
472
472
tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) &&
473
473
test_when_finished "remove_object $tag" &&
474
- echo $tag >.git/ refs/tags/wrong &&
474
+ git update-ref refs/tags/wrong $tag &&
475
475
test_when_finished "git update-ref -d refs/tags/wrong" &&
476
476
test_must_fail git fsck --tags 2>out &&
477
477
test_i18ngrep "error in tag $tag.*unterminated header: NUL at offset" out
0 commit comments