t: use hash-object --literally when created malformed objects
Many test scripts use hash-object to create malformed objects to see how we handle the results in various commands. In some cases we already have to use "hash-object --literally", because it does some rudimentary quality checks. But let's use "--literally" more consistently to future-proof these tests against hash-object learning to be more careful. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 18, 2023 at 15:41 UTC
34959d80db602b7d6893c9e2dfa81d78fd16f702
13 files changed
+27
-27
t/t1450-fsck.sh
+14
-14
@@ -212,7 +212,7 @@ test_expect_success 'email without @ is okay' '
212
test_expect_success 'email with embedded > is not okay' '
213
git cat-file commit HEAD >basis &&
214
sed "s/@[a-z]/&>/" basis >bad-email &&
215
- new=$(git hash-object -t commit -w --stdin <bad-email) &&
215
+ new=$(git hash-object --literally -t commit -w --stdin <bad-email) &&
216
test_when_finished "remove_object $new" &&
217
git update-ref refs/heads/bogus "$new" &&
218
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -223,7 +223,7 @@ test_expect_success 'email with embedded > is not okay' '
223
test_expect_success 'missing < email delimiter is reported nicely' '
224
git cat-file commit HEAD >basis &&
225
sed "s/<//" basis >bad-email-2 &&
226
- new=$(git hash-object -t commit -w --stdin <bad-email-2) &&
226
+ new=$(git hash-object --literally -t commit -w --stdin <bad-email-2) &&
227
test_when_finished "remove_object $new" &&
228
git update-ref refs/heads/bogus "$new" &&
229
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -234,7 +234,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
234
test_expect_success 'missing email is reported nicely' '
235
git cat-file commit HEAD >basis &&
236
sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 &&
237
- new=$(git hash-object -t commit -w --stdin <bad-email-3) &&
237
+ new=$(git hash-object --literally -t commit -w --stdin <bad-email-3) &&
238
test_when_finished "remove_object $new" &&
239
git update-ref refs/heads/bogus "$new" &&
240
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -245,7 +245,7 @@ test_expect_success 'missing email is reported nicely' '
245
test_expect_success '> in name is reported' '
246
git cat-file commit HEAD >basis &&
247
sed "s/ </> </" basis >bad-email-4 &&
248
- new=$(git hash-object -t commit -w --stdin <bad-email-4) &&
248
+ new=$(git hash-object --literally -t commit -w --stdin <bad-email-4) &&
249
test_when_finished "remove_object $new" &&
250
git update-ref refs/heads/bogus "$new" &&
251
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -258,7 +258,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
258
git cat-file commit HEAD >basis &&
259
sed "s/^\\(author .*>\\) [0-9]*/\\1 18446744073709551617/" \
260
<basis >bad-timestamp &&
261
- new=$(git hash-object -t commit -w --stdin <bad-timestamp) &&
261
+ new=$(git hash-object --literally -t commit -w --stdin <bad-timestamp) &&
262
test_when_finished "remove_object $new" &&
263
git update-ref refs/heads/bogus "$new" &&
264
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -269,7 +269,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
269
test_expect_success 'commit with NUL in header' '
270
git cat-file commit HEAD >basis &&
271
sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header &&
272
- new=$(git hash-object -t commit -w --stdin <commit-NUL-header) &&
272
+ new=$(git hash-object --literally -t commit -w --stdin <commit-NUL-header) &&
273
test_when_finished "remove_object $new" &&
274
git update-ref refs/heads/bogus "$new" &&
275
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -292,7 +292,7 @@ test_expect_success 'tree object with duplicate entries' '
292
git cat-file tree $T &&
293
git cat-file tree $T
294
) |
295
- git hash-object -w -t tree --stdin
295
+ git hash-object --literally -w -t tree --stdin
296
) &&
297
test_must_fail git fsck 2>out &&
298
test_i18ngrep "error in tree .*contains duplicate file entries" out
@@ -426,7 +426,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
426
This is an invalid tag.
427
EOF
428
429
- tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
429
+ tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
430
test_when_finished "remove_object $tag" &&
431
echo $tag >.git/refs/tags/wrong &&
432
test_when_finished "git update-ref -d refs/tags/wrong" &&
@@ -558,7 +558,7 @@ test_expect_success 'rev-list --verify-objects with commit graph (parent)' '
558
test_expect_success 'force fsck to ignore double author' '
559
git cat-file commit HEAD >basis &&
560
sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
561
- new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
561
+ new=$(git hash-object --literally -t commit -w --stdin <multiple-authors) &&
562
test_when_finished "remove_object $new" &&
563
git update-ref refs/heads/bogus "$new" &&
564
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -573,7 +573,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
573
(git init null-blob &&
574
cd null-blob &&
575
sha=$(printf "100644 file$_bz$_bzoid" |
576
- git hash-object -w --stdin -t tree) &&
576
+ git hash-object --literally -w --stdin -t tree) &&
577
git fsck 2>out &&
578
test_i18ngrep "warning.*null sha1" out
579
)
@@ -583,7 +583,7 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
583
(git init null-commit &&
584
cd null-commit &&
585
sha=$(printf "160000 submodule$_bz$_bzoid" |
586
- git hash-object -w --stdin -t tree) &&
586
+ git hash-object --literally -w --stdin -t tree) &&
587
git fsck 2>out &&
588
test_i18ngrep "warning.*null sha1" out
589
)
@@ -648,7 +648,7 @@ test_expect_success 'NUL in commit' '
648
git commit --allow-empty -m "initial commitQNUL after message" &&
649
git cat-file commit HEAD >original &&
650
q_to_nul <original >munged &&
651
- git hash-object -w -t commit --stdin <munged >name &&
651
+ git hash-object --literally -w -t commit --stdin <munged >name &&
652
git branch bad $(cat name) &&
653
654
test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 &&
@@ -794,8 +794,8 @@ test_expect_success 'fsck errors in packed objects' '
794
git cat-file commit HEAD >basis &&
795
sed "s/</one/" basis >one &&
796
sed "s/</foo/" basis >two &&
797
- one=$(git hash-object -t commit -w one) &&
798
- two=$(git hash-object -t commit -w two) &&
797
+ one=$(git hash-object --literally -t commit -w one) &&
798
+ two=$(git hash-object --literally -t commit -w two) &&
799
pack=$(
800
{
801
echo $one &&
t/t4054-diff-bogus-tree.sh
+1
-1
@@ -10,7 +10,7 @@ test_expect_success 'create bogus tree' '
10
bogus_tree=$(
11
printf "100644 fooQ$name" |
12
q_to_nul |
13
- git hash-object -w --stdin -t tree
13
+ git hash-object --literally -w --stdin -t tree
14
)
15
'
16
t/t4058-diff-duplicates.sh
+1
-1
@@ -29,7 +29,7 @@ make_tree () {
29
make_tree_entry "$1" "$2" "$3"
30
shift; shift; shift
31
done |
32
- git hash-object -w -t tree --stdin
32
+ git hash-object --literally -w -t tree --stdin
33
}
34
35
# this is kind of a convoluted setup, but matches
t/t4212-log-corrupt.sh
+2
-2
@@ -10,7 +10,7 @@ test_expect_success 'setup' '
10
11
git cat-file commit HEAD |
12
sed "/^author /s/>/>-<>/" >broken_email.commit &&
13
- git hash-object -w -t commit broken_email.commit >broken_email.hash &&
13
+ git hash-object --literally -w -t commit broken_email.commit >broken_email.hash &&
14
git update-ref refs/heads/broken_email $(cat broken_email.hash)
15
'
16
@@ -46,7 +46,7 @@ test_expect_success 'git log --format with broken author email' '
46
munge_author_date () {
47
git cat-file commit "$1" >commit.orig &&
48
sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
49
- git hash-object -w -t commit commit.munge
49
+ git hash-object --literally -w -t commit commit.munge
50
}
51
52
test_expect_success 'unparsable dates produce sentinel value' '
t/t5302-pack-index.sh
+1
-1
@@ -263,7 +263,7 @@ tag guten tag
263
This is an invalid tag.
264
EOF
265
266
- tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
266
+ tag=$(git hash-object -t tag -w --stdin --literally <wrong-tag) &&
267
pack1=$(echo $tag $sha | git pack-objects tag-test) &&
268
echo remove tag object &&
269
thirtyeight=${tag#??} &&
t/t5504-fetch-receive-strict.sh
+1
-1
@@ -138,7 +138,7 @@ This commit object intentionally broken
138
EOF
139
140
test_expect_success 'setup bogus commit' '
141
- commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
141
+ commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
142
'
143
144
test_expect_success 'fsck with no skipList input' '
t/t5702-protocol-v2.sh
+1
-1
@@ -1114,7 +1114,7 @@ test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object'
1114
1115
This commit object intentionally broken
1116
EOF
1117
- BOGUS=$(git -C "$P" hash-object -t commit -w --stdin <bogus-commit) &&
1117
+ BOGUS=$(git -C "$P" hash-object -t commit -w --stdin --literally <bogus-commit) &&
1118
git -C "$P" branch bogus-branch "$BOGUS" &&
1119
1120
echo my-blob >"$P/my-blob" &&
t/t6300-for-each-ref.sh
+1
-1
@@ -606,7 +606,7 @@ test_expect_success 'create tag without tagger' '
606
git tag -a -m "Broken tag" taggerless &&
607
git tag -f taggerless $(git cat-file tag taggerless |
608
sed -e "/^tagger /d" |
609
- git hash-object --stdin -w -t tag)
609
+ git hash-object --literally --stdin -w -t tag)
610
'
611
612
test_atom refs/tags/taggerless type 'commit'
t/t7509-commit-authorship.sh
+1
-1
@@ -105,7 +105,7 @@ test_expect_success '--amend option with empty author' '
105
test_expect_success '--amend option with missing author' '
106
git cat-file commit Initial >tmp &&
107
sed "s/author [^<]* </author </" tmp >malformed &&
108
- sha=$(git hash-object -t commit -w malformed) &&
108
+ sha=$(git hash-object --literally -t commit -w malformed) &&
109
test_when_finished "remove_object $sha" &&
110
git checkout $sha &&
111
test_when_finished "git checkout Initial" &&
t/t7510-signed-commit.sh
+1
-1
@@ -202,7 +202,7 @@ test_expect_success GPG 'detect fudged signature with NUL' '
202
git cat-file commit seventh-signed >raw &&
203
cat raw >forged2 &&
204
echo Qwik | tr "Q" "\000" >>forged2 &&
205
- git hash-object -w -t commit forged2 >forged2.commit &&
205
+ git hash-object --literally -w -t commit forged2 >forged2.commit &&
206
test_must_fail git verify-commit $(cat forged2.commit) &&
207
git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
208
grep "BAD signature from" actual2 &&
t/t7528-signed-commit-ssh.sh
+1
-1
@@ -270,7 +270,7 @@ test_expect_success GPGSSH 'detect fudged signature with NUL' '
270
git cat-file commit seventh-signed >raw &&
271
cat raw >forged2 &&
272
echo Qwik | tr "Q" "\000" >>forged2 &&
273
- git hash-object -w -t commit forged2 >forged2.commit &&
273
+ git hash-object --literally -w -t commit forged2 >forged2.commit &&
274
test_must_fail git verify-commit $(cat forged2.commit) &&
275
git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
276
grep "${GPGSSH_BAD_SIGNATURE}" actual2 &&
t/t8003-blame-corner-cases.sh
+1
-1
@@ -201,7 +201,7 @@ committer David Reiss <dreiss@facebook.com> 1234567890 +0000
201
202
some message
203
EOF
204
- COMMIT=$(git hash-object -t commit -w badcommit) &&
204
+ COMMIT=$(git hash-object --literally -t commit -w badcommit) &&
205
git --no-pager blame $COMMIT -- uno >/dev/null
206
'
207
t/t9350-fast-export.sh
+1
-1
@@ -373,7 +373,7 @@ EOF
373
374
test_expect_success 'cope with tagger-less tags' '
375
376
- TAG=$(git hash-object -t tag -w tag-content) &&
376
+ TAG=$(git hash-object --literally -t tag -w tag-content) &&
377
git update-ref refs/tags/sonnenschein $TAG &&
378
git fast-export -C -C --signed-tags=strip --all > output &&
379
test $(grep -c "^tag " output) = 4 &&