Skip to content

Commit 34959d8

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad5dfea commit 34959d8

13 files changed

+27
-27
lines changed

t/t1450-fsck.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ test_expect_success 'email without @ is okay' '
212212
test_expect_success 'email with embedded > is not okay' '
213213
git cat-file commit HEAD >basis &&
214214
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) &&
216216
test_when_finished "remove_object $new" &&
217217
git update-ref refs/heads/bogus "$new" &&
218218
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -223,7 +223,7 @@ test_expect_success 'email with embedded > is not okay' '
223223
test_expect_success 'missing < email delimiter is reported nicely' '
224224
git cat-file commit HEAD >basis &&
225225
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) &&
227227
test_when_finished "remove_object $new" &&
228228
git update-ref refs/heads/bogus "$new" &&
229229
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -234,7 +234,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
234234
test_expect_success 'missing email is reported nicely' '
235235
git cat-file commit HEAD >basis &&
236236
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) &&
238238
test_when_finished "remove_object $new" &&
239239
git update-ref refs/heads/bogus "$new" &&
240240
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -245,7 +245,7 @@ test_expect_success 'missing email is reported nicely' '
245245
test_expect_success '> in name is reported' '
246246
git cat-file commit HEAD >basis &&
247247
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) &&
249249
test_when_finished "remove_object $new" &&
250250
git update-ref refs/heads/bogus "$new" &&
251251
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -258,7 +258,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
258258
git cat-file commit HEAD >basis &&
259259
sed "s/^\\(author .*>\\) [0-9]*/\\1 18446744073709551617/" \
260260
<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) &&
262262
test_when_finished "remove_object $new" &&
263263
git update-ref refs/heads/bogus "$new" &&
264264
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -269,7 +269,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
269269
test_expect_success 'commit with NUL in header' '
270270
git cat-file commit HEAD >basis &&
271271
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) &&
273273
test_when_finished "remove_object $new" &&
274274
git update-ref refs/heads/bogus "$new" &&
275275
test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -292,7 +292,7 @@ test_expect_success 'tree object with duplicate entries' '
292292
git cat-file tree $T &&
293293
git cat-file tree $T
294294
) |
295-
git hash-object -w -t tree --stdin
295+
git hash-object --literally -w -t tree --stdin
296296
) &&
297297
test_must_fail git fsck 2>out &&
298298
test_i18ngrep "error in tree .*contains duplicate file entries" out
@@ -426,7 +426,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
426426
This is an invalid tag.
427427
EOF
428428
429-
tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
429+
tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
430430
test_when_finished "remove_object $tag" &&
431431
echo $tag >.git/refs/tags/wrong &&
432432
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)' '
558558
test_expect_success 'force fsck to ignore double author' '
559559
git cat-file commit HEAD >basis &&
560560
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) &&
562562
test_when_finished "remove_object $new" &&
563563
git update-ref refs/heads/bogus "$new" &&
564564
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' '
573573
(git init null-blob &&
574574
cd null-blob &&
575575
sha=$(printf "100644 file$_bz$_bzoid" |
576-
git hash-object -w --stdin -t tree) &&
576+
git hash-object --literally -w --stdin -t tree) &&
577577
git fsck 2>out &&
578578
test_i18ngrep "warning.*null sha1" out
579579
)
@@ -583,7 +583,7 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
583583
(git init null-commit &&
584584
cd null-commit &&
585585
sha=$(printf "160000 submodule$_bz$_bzoid" |
586-
git hash-object -w --stdin -t tree) &&
586+
git hash-object --literally -w --stdin -t tree) &&
587587
git fsck 2>out &&
588588
test_i18ngrep "warning.*null sha1" out
589589
)
@@ -648,7 +648,7 @@ test_expect_success 'NUL in commit' '
648648
git commit --allow-empty -m "initial commitQNUL after message" &&
649649
git cat-file commit HEAD >original &&
650650
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 &&
652652
git branch bad $(cat name) &&
653653
654654
test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 &&
@@ -794,8 +794,8 @@ test_expect_success 'fsck errors in packed objects' '
794794
git cat-file commit HEAD >basis &&
795795
sed "s/</one/" basis >one &&
796796
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) &&
799799
pack=$(
800800
{
801801
echo $one &&

t/t4054-diff-bogus-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_expect_success 'create bogus tree' '
1010
bogus_tree=$(
1111
printf "100644 fooQ$name" |
1212
q_to_nul |
13-
git hash-object -w --stdin -t tree
13+
git hash-object --literally -w --stdin -t tree
1414
)
1515
'
1616

t/t4058-diff-duplicates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ make_tree () {
2929
make_tree_entry "$1" "$2" "$3"
3030
shift; shift; shift
3131
done |
32-
git hash-object -w -t tree --stdin
32+
git hash-object --literally -w -t tree --stdin
3333
}
3434

3535
# this is kind of a convoluted setup, but matches

t/t4212-log-corrupt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_expect_success 'setup' '
1010
1111
git cat-file commit HEAD |
1212
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 &&
1414
git update-ref refs/heads/broken_email $(cat broken_email.hash)
1515
'
1616

@@ -46,7 +46,7 @@ test_expect_success 'git log --format with broken author email' '
4646
munge_author_date () {
4747
git cat-file commit "$1" >commit.orig &&
4848
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
5050
}
5151

5252
test_expect_success 'unparsable dates produce sentinel value' '

t/t5302-pack-index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ tag guten tag
263263
This is an invalid tag.
264264
EOF
265265
266-
tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
266+
tag=$(git hash-object -t tag -w --stdin --literally <wrong-tag) &&
267267
pack1=$(echo $tag $sha | git pack-objects tag-test) &&
268268
echo remove tag object &&
269269
thirtyeight=${tag#??} &&

t/t5504-fetch-receive-strict.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ This commit object intentionally broken
138138
EOF
139139

140140
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)"
142142
'
143143

144144
test_expect_success 'fsck with no skipList input' '

t/t5702-protocol-v2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object'
11141114
11151115
This commit object intentionally broken
11161116
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) &&
11181118
git -C "$P" branch bogus-branch "$BOGUS" &&
11191119
11201120
echo my-blob >"$P/my-blob" &&

t/t6300-for-each-ref.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ test_expect_success 'create tag without tagger' '
606606
git tag -a -m "Broken tag" taggerless &&
607607
git tag -f taggerless $(git cat-file tag taggerless |
608608
sed -e "/^tagger /d" |
609-
git hash-object --stdin -w -t tag)
609+
git hash-object --literally --stdin -w -t tag)
610610
'
611611

612612
test_atom refs/tags/taggerless type 'commit'

t/t7509-commit-authorship.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test_expect_success '--amend option with empty author' '
105105
test_expect_success '--amend option with missing author' '
106106
git cat-file commit Initial >tmp &&
107107
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) &&
109109
test_when_finished "remove_object $sha" &&
110110
git checkout $sha &&
111111
test_when_finished "git checkout Initial" &&

t/t7510-signed-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ test_expect_success GPG 'detect fudged signature with NUL' '
202202
git cat-file commit seventh-signed >raw &&
203203
cat raw >forged2 &&
204204
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 &&
206206
test_must_fail git verify-commit $(cat forged2.commit) &&
207207
git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
208208
grep "BAD signature from" actual2 &&

0 commit comments

Comments
 (0)