Skip to content

Commit a7b27d9

Browse files
committed
Merge branch 'bc/hash-independent-tests-part-4'
Update to the tests to help SHA-256 transition continues. * bc/hash-independent-tests-part-4: t2203: avoid hard-coded object ID values t1710: make hash independent t1007: remove SHA1 prerequisites t0090: make test pass with SHA-256 t0027: make hash size independent t6030: make test work with SHA-256 t5000: make hash independent t1450: make hash size independent t1410: make hash size independent t: add helper to convert object IDs to paths
2 parents a45f531 + f6c9b47 commit a7b27d9

11 files changed

+142
-93
lines changed

t/t0027-auto-crlf.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ compare_ws_file () {
1515
pfx=$1
1616
exp=$2.expect
1717
act=$pfx.actual.$3
18-
tr '\015\000abcdef0123456789' QN00000000000000000 <"$2" >"$exp" &&
19-
tr '\015\000abcdef0123456789' QN00000000000000000 <"$3" >"$act" &&
18+
tr '\015\000abcdef0123456789' QN00000000000000000 <"$2" |
19+
sed -e "s/0000*/$ZERO_OID/" >"$exp" &&
20+
tr '\015\000abcdef0123456789' QN00000000000000000 <"$3" |
21+
sed -e "s/0000*/$ZERO_OID/" >"$act" &&
2022
test_cmp "$exp" "$act" &&
2123
rm "$exp" "$act"
2224
}

t/t0090-cache-tree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
162162
'
163163

164164
test_expect_success PERL 'commit -p with shrinking cache-tree' '
165-
mkdir -p deep/subdir &&
166-
echo content >deep/subdir/file &&
165+
mkdir -p deep/very-long-subdir &&
166+
echo content >deep/very-long-subdir/file &&
167167
git add deep &&
168168
git commit -m add &&
169169
git rm -r deep &&

t/t1007-hash-object.sh

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ echo_without_newline() {
99
}
1010

1111
test_blob_does_not_exist() {
12-
test_expect_success SHA1 'blob does not exist in database' "
12+
test_expect_success 'blob does not exist in database' "
1313
test_must_fail git cat-file blob $1
1414
"
1515
}
1616

1717
test_blob_exists() {
18-
test_expect_success SHA1 'blob exists in database' "
18+
test_expect_success 'blob exists in database' "
1919
git cat-file blob $1
2020
"
2121
}
2222

2323
hello_content="Hello World"
24-
hello_sha1=5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
25-
2624
example_content="This is an example"
27-
example_sha1=ddd3f836d3e3fbb7ae289aa9ae83536f76956399
2825

2926
setup_repo() {
3027
echo_without_newline "$hello_content" > hello
@@ -44,7 +41,16 @@ pop_repo() {
4441
rm -rf $test_repo
4542
}
4643

47-
setup_repo
44+
test_expect_success 'setup' '
45+
setup_repo &&
46+
test_oid_cache <<-EOF
47+
hello sha1:5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
48+
hello sha256:1e3b6c04d2eeb2b3e45c8a330445404c0b7cc7b257e2b097167d26f5230090c4
49+
50+
example sha1:ddd3f836d3e3fbb7ae289aa9ae83536f76956399
51+
example sha256:b44fe1fe65589848253737db859bd490453510719d7424daab03daf0767b85ae
52+
EOF
53+
'
4854

4955
# Argument checking
5056

@@ -73,23 +79,23 @@ test_expect_success "Can't use --path with --no-filters" '
7379

7480
push_repo
7581

76-
test_expect_success SHA1 'hash a file' '
77-
test $hello_sha1 = $(git hash-object hello)
82+
test_expect_success 'hash a file' '
83+
test "$(test_oid hello)" = $(git hash-object hello)
7884
'
7985

80-
test_blob_does_not_exist $hello_sha1
86+
test_blob_does_not_exist "$(test_oid hello)"
8187

82-
test_expect_success SHA1 'hash from stdin' '
83-
test $example_sha1 = $(git hash-object --stdin < example)
88+
test_expect_success 'hash from stdin' '
89+
test "$(test_oid example)" = $(git hash-object --stdin < example)
8490
'
8591

86-
test_blob_does_not_exist $example_sha1
92+
test_blob_does_not_exist "$(test_oid example)"
8793

88-
test_expect_success SHA1 'hash a file and write to database' '
89-
test $hello_sha1 = $(git hash-object -w hello)
94+
test_expect_success 'hash a file and write to database' '
95+
test "$(test_oid hello)" = $(git hash-object -w hello)
9096
'
9197

92-
test_blob_exists $hello_sha1
98+
test_blob_exists "$(test_oid hello)"
9399

94100
test_expect_success 'git hash-object --stdin file1 <file0 first operates on file0, then file1' '
95101
echo foo > file1 &&
@@ -161,34 +167,34 @@ pop_repo
161167
for args in "-w --stdin" "--stdin -w"; do
162168
push_repo
163169

164-
test_expect_success SHA1 "hash from stdin and write to database ($args)" '
165-
test $example_sha1 = $(git hash-object $args < example)
170+
test_expect_success "hash from stdin and write to database ($args)" '
171+
test "$(test_oid example)" = $(git hash-object $args < example)
166172
'
167173

168-
test_blob_exists $example_sha1
174+
test_blob_exists "$(test_oid example)"
169175

170176
pop_repo
171177
done
172178

173179
filenames="hello
174180
example"
175181

176-
sha1s="$hello_sha1
177-
$example_sha1"
182+
oids="$(test_oid hello)
183+
$(test_oid example)"
178184

179-
test_expect_success SHA1 "hash two files with names on stdin" '
180-
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object --stdin-paths)"
185+
test_expect_success "hash two files with names on stdin" '
186+
test "$oids" = "$(echo_without_newline "$filenames" | git hash-object --stdin-paths)"
181187
'
182188

183189
for args in "-w --stdin-paths" "--stdin-paths -w"; do
184190
push_repo
185191

186-
test_expect_success SHA1 "hash two files with names on stdin and write to database ($args)" '
187-
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object $args)"
192+
test_expect_success "hash two files with names on stdin and write to database ($args)" '
193+
test "$oids" = "$(echo_without_newline "$filenames" | git hash-object $args)"
188194
'
189195

190-
test_blob_exists $hello_sha1
191-
test_blob_exists $example_sha1
196+
test_blob_exists "$(test_oid hello)"
197+
test_blob_exists "$(test_oid example)"
192198

193199
pop_repo
194200
done

t/t1410-reflog.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ check_fsck () {
3030
}
3131

3232
corrupt () {
33-
aa=${1%??????????????????????????????????????} zz=${1#??}
34-
mv .git/objects/$aa/$zz .git/$aa$zz
33+
mv .git/objects/$(test_oid_to_path $1) .git/$1
3534
}
3635

3736
recover () {
38-
aa=${1%??????????????????????????????????????} zz=${1#??}
37+
aa=$(echo $1 | cut -c 1-2)
3938
mkdir -p .git/objects/$aa
40-
mv .git/$aa$zz .git/objects/$aa/$zz
39+
mv .git/$1 .git/objects/$(test_oid_to_path $1)
4140
}
4241

4342
check_dont_have () {
@@ -55,6 +54,7 @@ check_dont_have () {
5554
}
5655

5756
test_expect_success setup '
57+
test_oid_init &&
5858
mkdir -p A/B &&
5959
echo rat >C &&
6060
echo ox >A/D &&
@@ -313,12 +313,12 @@ test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
313313
# Each line is 114 characters, so we need 75 to still have a few before the
314314
# last 8K. The 89-character padding on the final entry lines up our
315315
# newline exactly.
316-
test_expect_success 'parsing reverse reflogs at BUFSIZ boundaries' '
316+
test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' '
317317
git checkout -b reflogskip &&
318-
z38=00000000000000000000000000000000000000 &&
318+
zf=$(test_oid zero_2) &&
319319
ident="abc <xyz> 0000000001 +0000" &&
320320
for i in $(test_seq 1 75); do
321-
printf "$z38%02d $z38%02d %s\t" $i $(($i+1)) "$ident" &&
321+
printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" &&
322322
if test $i = 75; then
323323
for j in $(test_seq 1 89); do
324324
printf X
@@ -329,7 +329,7 @@ test_expect_success 'parsing reverse reflogs at BUFSIZ boundaries' '
329329
printf "\n"
330330
done >.git/logs/refs/heads/reflogskip &&
331331
git rev-parse reflogskip@{73} >actual &&
332-
echo ${z38}03 >expect &&
332+
echo ${zf}03 >expect &&
333333
test_cmp expect actual
334334
'
335335

t/t1450-fsck.sh

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_description='git fsck random collection of tests
99
. ./test-lib.sh
1010

1111
test_expect_success setup '
12+
test_oid_init &&
1213
git config gc.auto 0 &&
1314
git config i18n.commitencoding ISO-8859-1 &&
1415
test_commit A fileA one &&
@@ -54,8 +55,8 @@ test_expect_success 'setup: helpers for corruption tests' '
5455

5556
test_expect_success 'object with bad sha1' '
5657
sha=$(echo blob | git hash-object -w --stdin) &&
57-
old=$(echo $sha | sed "s+^..+&/+") &&
58-
new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
58+
old=$(test_oid_to_path "$sha") &&
59+
new=$(dirname $old)/$(test_oid ff_2) &&
5960
sha="$(dirname $new)$(basename $new)" &&
6061
mv .git/objects/$old .git/objects/$new &&
6162
test_when_finished "remove_object $sha" &&
@@ -84,7 +85,7 @@ test_expect_success 'branch pointing to non-commit' '
8485
test_expect_success 'HEAD link pointing at a funny object' '
8586
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
8687
mv .git/HEAD .git/SAVED_HEAD &&
87-
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
88+
echo $ZERO_OID >.git/HEAD &&
8889
# avoid corrupt/broken HEAD from interfering with repo discovery
8990
test_must_fail env GIT_DIR=.git git fsck 2>out &&
9091
cat out &&
@@ -244,10 +245,16 @@ test_expect_success 'tree object with duplicate entries' '
244245
'
245246

246247
test_expect_success 'unparseable tree object' '
248+
test_oid_cache <<-\EOF &&
249+
junk sha1:twenty-bytes-of-junk
250+
junk sha256:twenty-bytes-of-junk-twelve-more
251+
EOF
252+
247253
test_when_finished "git update-ref -d refs/heads/wrong" &&
248254
test_when_finished "remove_object \$tree_sha1" &&
249255
test_when_finished "remove_object \$commit_sha1" &&
250-
tree_sha1=$(printf "100644 \0twenty-bytes-of-junk" | git hash-object -t tree --stdin -w --literally) &&
256+
junk=$(test_oid junk) &&
257+
tree_sha1=$(printf "100644 \0$junk" | git hash-object -t tree --stdin -w --literally) &&
251258
commit_sha1=$(git commit-tree $tree_sha1) &&
252259
git update-ref refs/heads/wrong $commit_sha1 &&
253260
test_must_fail git fsck 2>out &&
@@ -275,8 +282,9 @@ test_expect_success 'tree entry with type mismatch' '
275282
'
276283

277284
test_expect_success 'tag pointing to nonexistent' '
278-
cat >invalid-tag <<-\EOF &&
279-
object ffffffffffffffffffffffffffffffffffffffff
285+
badoid=$(test_oid deadbeef) &&
286+
cat >invalid-tag <<-EOF &&
287+
object $badoid
280288
type commit
281289
tag invalid
282290
tagger T A Gger <[email protected]> 1234567890 -0000
@@ -386,8 +394,8 @@ test_expect_success 'rev-list --verify-objects' '
386394

387395
test_expect_success 'rev-list --verify-objects with bad sha1' '
388396
sha=$(echo blob | git hash-object -w --stdin) &&
389-
old=$(echo $sha | sed "s+^..+&/+") &&
390-
new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
397+
old=$(test_oid_to_path $sha) &&
398+
new=$(dirname $old)/$(test_oid ff_2) &&
391399
sha="$(dirname $new)$(basename $new)" &&
392400
mv .git/objects/$old .git/objects/$new &&
393401
test_when_finished "remove_object $sha" &&
@@ -402,7 +410,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
402410
403411
test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
404412
cat out &&
405-
test_i18ngrep -q "error: hash mismatch 63ffffffffffffffffffffffffffffffffffffff" out
413+
test_i18ngrep -q "error: hash mismatch $(dirname $new)$(test_oid ff_2)" out
406414
'
407415

408416
test_expect_success 'force fsck to ignore double author' '
@@ -417,13 +425,12 @@ test_expect_success 'force fsck to ignore double author' '
417425
'
418426

419427
_bz='\0'
420-
_bz5="$_bz$_bz$_bz$_bz$_bz"
421-
_bz20="$_bz5$_bz5$_bz5$_bz5"
428+
_bzoid=$(printf $ZERO_OID | sed -e 's/00/\\0/g')
422429

423430
test_expect_success 'fsck notices blob entry pointing to null sha1' '
424431
(git init null-blob &&
425432
cd null-blob &&
426-
sha=$(printf "100644 file$_bz$_bz20" |
433+
sha=$(printf "100644 file$_bz$_bzoid" |
427434
git hash-object -w --stdin -t tree) &&
428435
git fsck 2>out &&
429436
cat out &&
@@ -434,7 +441,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
434441
test_expect_success 'fsck notices submodule entry pointing to null sha1' '
435442
(git init null-commit &&
436443
cd null-commit &&
437-
sha=$(printf "160000 submodule$_bz$_bz20" |
444+
sha=$(printf "160000 submodule$_bz$_bzoid" |
438445
git hash-object -w --stdin -t tree) &&
439446
git fsck 2>out &&
440447
cat out &&
@@ -586,7 +593,7 @@ test_expect_success 'fsck --connectivity-only' '
586593
# its type. That lets us see that --connectivity-only is
587594
# not actually looking at the contents, but leaves it
588595
# free to examine the type if it chooses.
589-
empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
596+
empty=.git/objects/$(test_oid_to_path $EMPTY_BLOB) &&
590597
blob=$(echo unrelated | git hash-object -w --stdin) &&
591598
mv -f $(sha1_file $blob) $empty &&
592599
@@ -631,10 +638,12 @@ test_expect_success 'fsck --name-objects' '
631638

632639
test_expect_success 'alternate objects are correctly blamed' '
633640
test_when_finished "rm -rf alt.git .git/objects/info/alternates" &&
641+
name=$(test_oid numeric) &&
642+
path=$(test_oid_to_path "$name") &&
634643
git init --bare alt.git &&
635644
echo "../../alt.git/objects" >.git/objects/info/alternates &&
636-
mkdir alt.git/objects/12 &&
637-
>alt.git/objects/12/34567890123456789012345678901234567890 &&
645+
mkdir alt.git/objects/$(dirname $path) &&
646+
>alt.git/objects/$(dirname $path)/$(basename $path) &&
638647
test_must_fail git fsck >out 2>&1 &&
639648
test_i18ngrep alt.git out
640649
'

0 commit comments

Comments
 (0)