Skip to content

Commit 709f9f5

Browse files
committed
Merge branch 'bc/hash-independent-tests'
Tests that rely on the exact hardcoded values of object names have been updated in preparation for hash function migration. * bc/hash-independent-tests: t2107: abstract away SHA-1-specific constants t2101: abstract away SHA-1-specific constants t2101: modernize test style t2020: abstract away SHA-1 specific constants t1507: abstract away SHA-1-specific constants t1411: abstract away SHA-1-specific constants t1405: sort reflog entries in a hash-independent way t1300: abstract away SHA-1-specific constants t1304: abstract away SHA-1-specific constants t1011: abstract away SHA-1-specific constants
2 parents cd94dd0 + 31bdb1f commit 709f9f5

9 files changed

+100
-82
lines changed

t/t1011-read-tree-sparse-checkout.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ test_description='sparse checkout tests
1515
. "$TEST_DIRECTORY"/lib-read-tree.sh
1616

1717
test_expect_success 'setup' '
18+
test_commit init &&
19+
echo modified >>init.t &&
20+
1821
cat >expected <<-EOF &&
19-
100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t
22+
100644 $(git hash-object init.t) 0 init.t
2023
100644 $EMPTY_BLOB 0 sub/added
2124
100644 $EMPTY_BLOB 0 sub/addedtoo
2225
100644 $EMPTY_BLOB 0 subsub/added
@@ -28,8 +31,6 @@ test_expect_success 'setup' '
2831
H subsub/added
2932
EOF
3033
31-
test_commit init &&
32-
echo modified >>init.t &&
3334
mkdir sub subsub &&
3435
touch sub/added sub/addedtoo subsub/added &&
3536
git add init.t sub/added sub/addedtoo subsub/added &&

t/t1300-repo-config.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,10 +1587,10 @@ test_expect_success '--show-origin stdin with file include' '
15871587
'
15881588

15891589
test_expect_success !MINGW '--show-origin blob' '
1590-
cat >expect <<-\EOF &&
1591-
blob:a9d9f9e555b5c6f07cbe09d3f06fe3df11e09c08 user.custom=true
1592-
EOF
15931590
blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1591+
cat >expect <<-EOF &&
1592+
blob:$blob user.custom=true
1593+
EOF
15941594
git config --blob=$blob --show-origin --list >output &&
15951595
test_cmp expect output
15961596
'

t/t1304-default-acl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test_expect_success SETFACL 'Setup test repo' '
5454

5555
test_expect_success SETFACL 'Objects creation does not break ACLs with restrictive umask' '
5656
# SHA1 for empty blob
57-
check_perms_and_acl .git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
57+
check_perms_and_acl .git/objects/$(echo $EMPTY_BLOB | sed -e "s,^\(..\),\1/,")
5858
'
5959

6060
test_expect_success SETFACL 'git gc does not break ACLs with restrictive umask' '

t/t1405-main-ref-store.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test_expect_success 'rename_refs(master, new-master)' '
4545
'
4646

4747
test_expect_success 'for_each_ref(refs/heads/)' '
48-
$RUN for-each-ref refs/heads/ | cut -c 42- >actual &&
48+
$RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
4949
cat >expected <<-\EOF &&
5050
master 0x0
5151
new-master 0x0
@@ -71,7 +71,7 @@ test_expect_success 'verify_ref(new-master)' '
7171
'
7272

7373
test_expect_success 'for_each_reflog()' '
74-
$RUN for-each-reflog | sort | cut -c 42- >actual &&
74+
$RUN for-each-reflog | sort -k2 | cut -c 42- >actual &&
7575
cat >expected <<-\EOF &&
7676
HEAD 0x1
7777
refs/heads/master 0x0

t/t1411-reflog-show.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test_expect_success 'setup' '
1010
git commit -m one
1111
'
1212

13+
commit=$(git rev-parse --short HEAD)
1314
cat >expect <<'EOF'
1415
Reflog: HEAD@{0} (C O Mitter <[email protected]>)
1516
Reflog message: commit (initial): one
@@ -20,8 +21,8 @@ test_expect_success 'log -g shows reflog headers' '
2021
test_cmp expect actual
2122
'
2223

23-
cat >expect <<'EOF'
24-
e46513e HEAD@{0}: commit (initial): one
24+
cat >expect <<EOF
25+
$commit HEAD@{0}: commit (initial): one
2526
EOF
2627
test_expect_success 'oneline reflog format' '
2728
git log -g -1 --oneline >actual &&
@@ -33,8 +34,8 @@ test_expect_success 'reflog default format' '
3334
test_cmp expect actual
3435
'
3536

36-
cat >expect <<'EOF'
37-
commit e46513e
37+
cat >expect <<EOF
38+
commit $commit
3839
Reflog: HEAD@{0} (C O Mitter <[email protected]>)
3940
Reflog message: commit (initial): one
4041
Author: A U Thor <[email protected]>
@@ -56,8 +57,8 @@ test_expect_success 'using @{now} syntax shows reflog date (multiline)' '
5657
test_cmp expect actual
5758
'
5859

59-
cat >expect <<'EOF'
60-
e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
60+
cat >expect <<EOF
61+
$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
6162
EOF
6263
test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
6364
git log -g -1 --oneline HEAD@{now} >actual &&
@@ -82,8 +83,8 @@ test_expect_success 'using --date= shows reflog date (multiline)' '
8283
test_cmp expect actual
8384
'
8485

85-
cat >expect <<'EOF'
86-
e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
86+
cat >expect <<EOF
87+
$commit HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
8788
EOF
8889
test_expect_success 'using --date= shows reflog date (oneline)' '
8990
git log -g -1 --oneline --date=default >actual &&
@@ -109,8 +110,8 @@ test_expect_success 'log.date does not invoke "--date" magic (multiline)' '
109110
test_cmp expect actual
110111
'
111112

112-
cat >expect <<'EOF'
113-
e46513e HEAD@{0}: commit (initial): one
113+
cat >expect <<EOF
114+
$commit HEAD@{0}: commit (initial): one
114115
EOF
115116
test_expect_success 'log.date does not invoke "--date" magic (oneline)' '
116117
test_config log.date raw &&

t/t1507-rev-parse-upstream.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ test_expect_success '@{u} works when tracking a local branch' '
209209
test refs/heads/master = "$(full_name @{u})"
210210
'
211211

212+
commit=$(git rev-parse HEAD)
212213
cat >expect <<EOF
213-
commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
214+
commit $commit
214215
Reflog: master@{0} (C O Mitter <[email protected]>)
215216
Reflog message: branch: Created from HEAD
216217
Author: A U Thor <[email protected]>
@@ -224,7 +225,7 @@ test_expect_success 'log -g other@{u}' '
224225
'
225226

226227
cat >expect <<EOF
227-
commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
228+
commit $commit
228229
Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <[email protected]>)
229230
Reflog message: branch: Created from HEAD
230231
Author: A U Thor <[email protected]>

t/t2020-checkout-detach.sh

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ test_expect_success 'no advice given for explicit detached head state' '
189189
# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (new format)
190190
test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not asked to' "
191191
192+
commit=$(git rev-parse --short=12 master^) &&
193+
commit2=$(git rev-parse --short=12 master~2) &&
194+
commit3=$(git rev-parse --short=12 master~3) &&
195+
192196
# The first detach operation is more chatty than the following ones.
193-
cat >1st_detach <<-'EOF' &&
197+
cat >1st_detach <<-EOF &&
194198
Note: checking out 'HEAD^'.
195199
196200
You are in 'detached HEAD' state. You can look around, make experimental
@@ -202,18 +206,18 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as
202206
203207
git checkout -b <new-branch-name>
204208
205-
HEAD is now at 7c7cd714e262 three
209+
HEAD is now at \$commit three
206210
EOF
207211
208212
# The remaining ones just show info about previous and current HEADs.
209-
cat >2nd_detach <<-'EOF' &&
210-
Previous HEAD position was 7c7cd714e262 three
211-
HEAD is now at 139b20d8e6c5 two
213+
cat >2nd_detach <<-EOF &&
214+
Previous HEAD position was \$commit three
215+
HEAD is now at \$commit2 two
212216
EOF
213217
214-
cat >3rd_detach <<-'EOF' &&
215-
Previous HEAD position was 139b20d8e6c5 two
216-
HEAD is now at d79ce1670bdc one
218+
cat >3rd_detach <<-EOF &&
219+
Previous HEAD position was \$commit2 two
220+
HEAD is now at \$commit3 one
217221
EOF
218222
219223
reset &&
@@ -261,8 +265,12 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as
261265
# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (old format)
262266
test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked to' "
263267
268+
commit=$(git rev-parse --short=12 master^) &&
269+
commit2=$(git rev-parse --short=12 master~2) &&
270+
commit3=$(git rev-parse --short=12 master~3) &&
271+
264272
# The first detach operation is more chatty than the following ones.
265-
cat >1st_detach <<-'EOF' &&
273+
cat >1st_detach <<-EOF &&
266274
Note: checking out 'HEAD^'.
267275
268276
You are in 'detached HEAD' state. You can look around, make experimental
@@ -274,18 +282,18 @@ test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked
274282
275283
git checkout -b <new-branch-name>
276284
277-
HEAD is now at 7c7cd714e262... three
285+
HEAD is now at \$commit... three
278286
EOF
279287
280288
# The remaining ones just show info about previous and current HEADs.
281-
cat >2nd_detach <<-'EOF' &&
282-
Previous HEAD position was 7c7cd714e262... three
283-
HEAD is now at 139b20d8e6c5... two
289+
cat >2nd_detach <<-EOF &&
290+
Previous HEAD position was \$commit... three
291+
HEAD is now at \$commit2... two
284292
EOF
285293
286-
cat >3rd_detach <<-'EOF' &&
287-
Previous HEAD position was 139b20d8e6c5... two
288-
HEAD is now at d79ce1670bdc... one
294+
cat >3rd_detach <<-EOF &&
295+
Previous HEAD position was \$commit2... two
296+
HEAD is now at \$commit3... one
289297
EOF
290298
291299
reset &&

t/t2101-update-index-reupdate.sh

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ test_description='git update-index --again test.
88

99
. ./test-lib.sh
1010

11-
cat > expected <<\EOF
12-
100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0 file1
13-
100644 9db8893856a8a02eaa73470054b7c1c5a7c82e47 0 file2
14-
EOF
15-
test_expect_success 'update-index --add' \
16-
'echo hello world >file1 &&
17-
echo goodbye people >file2 &&
18-
git update-index --add file1 file2 &&
19-
git ls-files -s >current &&
20-
cmp current expected'
11+
test_expect_success 'update-index --add' '
12+
echo hello world >file1 &&
13+
echo goodbye people >file2 &&
14+
git update-index --add file1 file2 &&
15+
git ls-files -s >current &&
16+
cat >expected <<-EOF &&
17+
100644 $(git hash-object file1) 0 file1
18+
100644 $(git hash-object file2) 0 file2
19+
EOF
20+
cmp current expected
21+
'
2122

22-
test_expect_success 'update-index --again' \
23-
'rm -f file1 &&
23+
test_expect_success 'update-index --again' '
24+
rm -f file1 &&
2425
echo hello everybody >file2 &&
2526
if git update-index --again
2627
then
@@ -29,56 +30,62 @@ test_expect_success 'update-index --again' \
2930
else
3031
echo happy - failed as expected
3132
fi &&
32-
git ls-files -s >current &&
33-
cmp current expected'
33+
git ls-files -s >current &&
34+
cmp current expected
35+
'
3436

35-
cat > expected <<\EOF
36-
100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0 file2
37-
EOF
38-
test_expect_success 'update-index --remove --again' \
39-
'git update-index --remove --again &&
40-
git ls-files -s >current &&
41-
cmp current expected'
37+
test_expect_success 'update-index --remove --again' '
38+
git update-index --remove --again &&
39+
git ls-files -s >current &&
40+
cat >expected <<-EOF &&
41+
100644 $(git hash-object file2) 0 file2
42+
EOF
43+
cmp current expected
44+
'
4245

4346
test_expect_success 'first commit' 'git commit -m initial'
4447

45-
cat > expected <<\EOF
46-
100644 53ab446c3f4e42ce9bb728a0ccb283a101be4979 0 dir1/file3
47-
100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0 file2
48-
EOF
49-
test_expect_success 'update-index again' \
50-
'mkdir -p dir1 &&
48+
test_expect_success 'update-index again' '
49+
mkdir -p dir1 &&
5150
echo hello world >dir1/file3 &&
5251
echo goodbye people >file2 &&
5352
git update-index --add file2 dir1/file3 &&
5453
echo hello everybody >file2 &&
5554
echo happy >dir1/file3 &&
5655
git update-index --again &&
5756
git ls-files -s >current &&
58-
cmp current expected'
57+
cat >expected <<-EOF &&
58+
100644 $(git hash-object dir1/file3) 0 dir1/file3
59+
100644 $(git hash-object file2) 0 file2
60+
EOF
61+
cmp current expected
62+
'
5963

60-
cat > expected <<\EOF
61-
100644 d7fb3f695f06c759dbf3ab00046e7cc2da22d10f 0 dir1/file3
62-
100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0 file2
63-
EOF
64-
test_expect_success 'update-index --update from subdir' \
65-
'echo not so happy >file2 &&
64+
file2=$(git hash-object file2)
65+
test_expect_success 'update-index --update from subdir' '
66+
echo not so happy >file2 &&
6667
(cd dir1 &&
6768
cat ../file2 >file3 &&
6869
git update-index --again
6970
) &&
7071
git ls-files -s >current &&
71-
cmp current expected'
72+
cat >expected <<-EOF &&
73+
100644 $(git hash-object dir1/file3) 0 dir1/file3
74+
100644 $file2 0 file2
75+
EOF
76+
test_cmp current expected
77+
'
7278

73-
cat > expected <<\EOF
74-
100644 594fb5bb1759d90998e2bf2a38261ae8e243c760 0 dir1/file3
75-
100644 0f1ae1422c2bf43f117d3dbd715c988a9ed2103f 0 file2
76-
EOF
77-
test_expect_success 'update-index --update with pathspec' \
78-
'echo very happy >file2 &&
79+
test_expect_success 'update-index --update with pathspec' '
80+
echo very happy >file2 &&
7981
cat file2 >dir1/file3 &&
8082
git update-index --again dir1/ &&
8183
git ls-files -s >current &&
82-
cmp current expected'
84+
cat >expected <<-EOF &&
85+
100644 $(git hash-object dir1/file3) 0 dir1/file3
86+
100644 $file2 0 file2
87+
EOF
88+
cmp current expected
89+
'
8390

8491
test_done

t/t2107-update-index-basic.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
8585
>B &&
8686
git add A B &&
8787
git update-index --chmod=+x A --chmod=-x B &&
88-
cat >expect <<-\EOF &&
89-
100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 A
90-
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 B
88+
cat >expect <<-EOF &&
89+
100755 $EMPTY_BLOB 0 A
90+
100644 $EMPTY_BLOB 0 B
9191
EOF
9292
git ls-files --stage A B >actual &&
9393
test_cmp expect actual

0 commit comments

Comments
 (0)