Skip to content

Commit 75fe818

Browse files
bk2204gitster
authored andcommitted
t4008: abstract away SHA-1-specific constants
Adjust the test so that it computes variables for blobs instead of using hard-coded hashes. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 31fb3f4 commit 75fe818

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

t/t4008-diff-break-rewrite.sh

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,32 @@ Further, with -B and -M together, these should turn into two renames.
2727
test_expect_success setup '
2828
cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
2929
cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
30+
blob0_id=$(git hash-object file0) &&
31+
blob1_id=$(git hash-object file1) &&
3032
git update-index --add file0 file1 &&
3133
git tag reference $(git write-tree)
3234
'
3335

3436
test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
3537
sed -e "s/git/GIT/" file0 >file1 &&
38+
blob2_id=$(git hash-object file1) &&
3639
rm -f file0 &&
3740
git update-index --remove file0 file1
3841
'
3942

4043
test_expect_success 'run diff with -B (#1)' '
4144
git diff-index -B --cached reference >current &&
42-
cat >expect <<-\EOF &&
43-
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
44-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
45+
cat >expect <<-EOF &&
46+
:100644 000000 $blob0_id $ZERO_OID D file0
47+
:100644 100644 $blob1_id $blob2_id M100 file1
4548
EOF
4649
compare_diff_raw expect current
4750
'
4851

4952
test_expect_success 'run diff with -B and -M (#2)' '
5053
git diff-index -B -M reference >current &&
51-
cat >expect <<-\EOF &&
52-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
54+
cat >expect <<-EOF &&
55+
:100644 100644 $blob0_id $blob2_id R100 file0 file1
5356
EOF
5457
compare_diff_raw expect current
5558
'
@@ -66,33 +69,34 @@ test_expect_success 'swap file0 and file1' '
6669

6770
test_expect_success 'run diff with -B (#3)' '
6871
git diff-index -B reference >current &&
69-
cat >expect <<-\EOF &&
70-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
71-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
72+
cat >expect <<-EOF &&
73+
:100644 100644 $blob0_id $blob1_id M100 file0
74+
:100644 100644 $blob1_id $blob0_id M100 file1
7275
EOF
7376
compare_diff_raw expect current
7477
'
7578

7679
test_expect_success 'run diff with -B and -M (#4)' '
7780
git diff-index -B -M reference >current &&
78-
cat >expect <<-\EOF &&
79-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
80-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
81+
cat >expect <<-EOF &&
82+
:100644 100644 $blob1_id $blob1_id R100 file1 file0
83+
:100644 100644 $blob0_id $blob0_id R100 file0 file1
8184
EOF
8285
compare_diff_raw expect current
8386
'
8487

8588
test_expect_success 'make file0 into something completely different' '
8689
rm -f file0 &&
8790
test_ln_s_add frotz file0 &&
91+
slink_id=$(printf frotz | git hash-object --stdin) &&
8892
git update-index file1
8993
'
9094

9195
test_expect_success 'run diff with -B (#5)' '
9296
git diff-index -B reference >current &&
93-
cat >expect <<-\EOF &&
94-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
95-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
97+
cat >expect <<-EOF &&
98+
:100644 120000 $blob0_id $slink_id T file0
99+
:100644 100644 $blob1_id $blob0_id M100 file1
96100
EOF
97101
compare_diff_raw expect current
98102
'
@@ -103,9 +107,9 @@ test_expect_success 'run diff with -B -M (#6)' '
103107
# file0 changed from regular to symlink. file1 is the same as the preimage
104108
# of file0. Because the change does not make file0 disappear, file1 is
105109
# denoted as a copy of file0
106-
cat >expect <<-\EOF &&
107-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
108-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
110+
cat >expect <<-EOF &&
111+
:100644 120000 $blob0_id $slink_id T file0
112+
:100644 100644 $blob0_id $blob0_id C file0 file1
109113
EOF
110114
compare_diff_raw expect current
111115
'
@@ -115,9 +119,9 @@ test_expect_success 'run diff with -M (#7)' '
115119
116120
# This should not mistake file0 as the copy source of new file1
117121
# due to type differences.
118-
cat >expect <<-\EOF &&
119-
:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
120-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
122+
cat >expect <<-EOF &&
123+
:100644 120000 $blob0_id $slink_id T file0
124+
:100644 100644 $blob1_id $blob0_id M file1
121125
EOF
122126
compare_diff_raw expect current
123127
'
@@ -128,25 +132,26 @@ test_expect_success 'file1 edited to look like file0 and file0 rename-edited to
128132
git checkout-index -f -u -a &&
129133
sed -e "s/git/GIT/" file0 >file1 &&
130134
sed -e "s/git/GET/" file0 >file2 &&
135+
blob3_id=$(git hash-object file2) &&
131136
rm -f file0 &&
132137
git update-index --add --remove file0 file1 file2
133138
'
134139

135140
test_expect_success 'run diff with -B (#8)' '
136141
git diff-index -B reference >current &&
137-
cat >expect <<-\EOF &&
138-
:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
139-
:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
140-
:000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
142+
cat >expect <<-EOF &&
143+
:100644 000000 $blob0_id $ZERO_OID D file0
144+
:100644 100644 $blob1_id $blob2_id M100 file1
145+
:000000 100644 $ZERO_OID $blob3_id A file2
141146
EOF
142147
compare_diff_raw expect current
143148
'
144149

145150
test_expect_success 'run diff with -B -C (#9)' '
146151
git diff-index -B -C reference >current &&
147-
cat >expect <<-\EOF &&
148-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
149-
:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
152+
cat >expect <<-EOF &&
153+
:100644 100644 $blob0_id $blob2_id C095 file0 file1
154+
:100644 100644 $blob0_id $blob3_id R095 file0 file2
150155
EOF
151156
compare_diff_raw expect current
152157
'

0 commit comments

Comments
 (0)