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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 21, 2018 at 02:01 UTC 75fe81844211ea58e657d031bc80efbc5f068bab
1 file changed +32 -27
t/t4008-diff-break-rewrite.sh
+32 -27
@@ -27,29 +27,32 @@ Further, with -B and -M together, these should turn into two renames.
27 test_expect_success setup '
28 cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
29 cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
30 + blob0_id=$(git hash-object file0) &&
31 + blob1_id=$(git hash-object file1) &&
32 git update-index --add file0 file1 &&
33 git tag reference $(git write-tree)
34 '
35
36 test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
37 sed -e "s/git/GIT/" file0 >file1 &&
38 + blob2_id=$(git hash-object file1) &&
39 rm -f file0 &&
40 git update-index --remove file0 file1
41 '
42
43 test_expect_success 'run diff with -B (#1)' '
44 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
48 EOF
49 compare_diff_raw expect current
50 '
51
52 test_expect_success 'run diff with -B and -M (#2)' '
53 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
56 EOF
57 compare_diff_raw expect current
58 '
@@ -66,18 +69,18 @@ test_expect_success 'swap file0 and file1' '
69
70 test_expect_success 'run diff with -B (#3)' '
71 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
75 EOF
76 compare_diff_raw expect current
77 '
78
79 test_expect_success 'run diff with -B and -M (#4)' '
80 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
84 EOF
85 compare_diff_raw expect current
86 '
@@ -85,14 +88,15 @@ test_expect_success 'run diff with -B and -M (#4)' '
88 test_expect_success 'make file0 into something completely different' '
89 rm -f file0 &&
90 test_ln_s_add frotz file0 &&
91 + slink_id=$(printf frotz | git hash-object --stdin) &&
92 git update-index file1
93 '
94
95 test_expect_success 'run diff with -B (#5)' '
96 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
100 EOF
101 compare_diff_raw expect current
102 '
@@ -103,9 +107,9 @@ test_expect_success 'run diff with -B -M (#6)' '
107 # file0 changed from regular to symlink. file1 is the same as the preimage
108 # of file0. Because the change does not make file0 disappear, file1 is
109 # 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
113 EOF
114 compare_diff_raw expect current
115 '
@@ -115,9 +119,9 @@ test_expect_success 'run diff with -M (#7)' '
119
120 # This should not mistake file0 as the copy source of new file1
121 # 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
125 EOF
126 compare_diff_raw expect current
127 '
@@ -128,25 +132,26 @@ test_expect_success 'file1 edited to look like file0 and file0 rename-edited to
132 git checkout-index -f -u -a &&
133 sed -e "s/git/GIT/" file0 >file1 &&
134 sed -e "s/git/GET/" file0 >file2 &&
135 + blob3_id=$(git hash-object file2) &&
136 rm -f file0 &&
137 git update-index --add --remove file0 file1 file2
138 '
139
140 test_expect_success 'run diff with -B (#8)' '
141 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
146 EOF
147 compare_diff_raw expect current
148 '
149
150 test_expect_success 'run diff with -B -C (#9)' '
151 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
155 EOF
156 compare_diff_raw expect current
157 '