t4300: abstract away SHA-1-specific constants
Adjust the test so that it computes values for object IDs instead of using hard-coded hashes. Move the heredocs later in the tests so we can take advantage of computed values. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Dec 21, 2019 at 19:49 UTC
525a7f176980439fb1c32a34b705b06bcb7033f1
1 file changed
+94
-94
t/t4300-merge-tree.sh
+94
-94
@@ -11,16 +11,16 @@ test_expect_success setup '
11
'
12
13
test_expect_success 'file add A, !B' '
14
- cat >expected <<\EXPECTED &&
14
+ git reset --hard initial &&
15
+ test_commit "add-a-not-b" "ONE" "AAA" &&
16
+ git merge-tree initial initial add-a-not-b >actual &&
17
+ cat >expected <<EXPECTED &&
18
added in remote
16
- their 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
19
+ their 100644 $(git rev-parse HEAD:ONE) ONE
20
@@ -0,0 +1 @@
21
+AAA
22
EXPECTED
23
21
- git reset --hard initial &&
22
- test_commit "add-a-not-b" "ONE" "AAA" &&
23
- git merge-tree initial initial add-a-not-b >actual &&
24
test_cmp expected actual
25
'
26
@@ -41,10 +41,15 @@ test_expect_success 'file add A, B (same)' '
41
'
42
43
test_expect_success 'file add A, B (different)' '
44
- cat >expected <<\EXPECTED &&
44
+ git reset --hard initial &&
45
+ test_commit "add-a-b-diff-A" "ONE" "AAA" &&
46
+ git reset --hard initial &&
47
+ test_commit "add-a-b-diff-B" "ONE" "BBB" &&
48
+ git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
49
+ cat >expected <<EXPECTED &&
50
added in both
46
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
47
- their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
51
+ our 100644 $(git rev-parse add-a-b-diff-A:ONE) ONE
52
+ their 100644 $(git rev-parse add-a-b-diff-B:ONE) ONE
53
@@ -1 +1,5 @@
54
+<<<<<<< .our
55
AAA
@@ -53,11 +58,6 @@ added in both
58
+>>>>>>> .their
59
EXPECTED
60
56
- git reset --hard initial &&
57
- test_commit "add-a-b-diff-A" "ONE" "AAA" &&
58
- git reset --hard initial &&
59
- test_commit "add-a-b-diff-B" "ONE" "BBB" &&
60
- git merge-tree initial add-a-b-diff-A add-a-b-diff-B >actual &&
61
test_cmp expected actual
62
'
63
@@ -69,18 +69,18 @@ test_expect_success 'file change A, !B' '
69
'
70
71
test_expect_success 'file change !A, B' '
72
- cat >expected <<\EXPECTED &&
72
+ git reset --hard initial &&
73
+ test_commit "change-not-a-b" "initial-file" "BBB" &&
74
+ git merge-tree initial initial change-not-a-b >actual &&
75
+ cat >expected <<EXPECTED &&
76
merged
74
- result 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
75
- our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
77
+ result 100644 $(git rev-parse change-a-not-b:initial-file) initial-file
78
+ our 100644 $(git rev-parse initial:initial-file ) initial-file
79
@@ -1 +1 @@
80
-initial
81
+BBB
82
EXPECTED
83
81
- git reset --hard initial &&
82
- test_commit "change-not-a-b" "initial-file" "BBB" &&
83
- git merge-tree initial initial change-not-a-b >actual &&
84
test_cmp expected actual
85
'
86
@@ -94,11 +94,16 @@ test_expect_success 'file change A, B (same)' '
94
'
95
96
test_expect_success 'file change A, B (different)' '
97
- cat >expected <<\EXPECTED &&
97
+ git reset --hard initial &&
98
+ test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
99
+ git reset --hard initial &&
100
+ test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
101
+ git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
102
+ cat >expected <<EXPECTED &&
103
changed in both
99
- base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
100
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d initial-file
101
- their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 initial-file
104
+ base 100644 $(git rev-parse initial:initial-file ) initial-file
105
+ our 100644 $(git rev-parse change-a-b-diff-A:initial-file) initial-file
106
+ their 100644 $(git rev-parse change-a-b-diff-B:initial-file) initial-file
107
@@ -1 +1,5 @@
108
+<<<<<<< .our
109
AAA
@@ -107,34 +112,10 @@ changed in both
112
+>>>>>>> .their
113
EXPECTED
114
110
- git reset --hard initial &&
111
- test_commit "change-a-b-diff-A" "initial-file" "AAA" &&
112
- git reset --hard initial &&
113
- test_commit "change-a-b-diff-B" "initial-file" "BBB" &&
114
- git merge-tree initial change-a-b-diff-A change-a-b-diff-B >actual &&
115
test_cmp expected actual
116
'
117
118
test_expect_success 'file change A, B (mixed)' '
119
- cat >expected <<\EXPECTED &&
120
-changed in both
121
- base 100644 f4f1f998c7776568c4ff38f516d77fef9399b5a7 ONE
122
- our 100644 af14c2c3475337c73759d561ef70b59e5c731176 ONE
123
- their 100644 372d761493f524d44d59bd24700c3bdf914c973c ONE
124
-@@ -7,7 +7,11 @@
125
- AAA
126
- AAA
127
- AAA
128
-+<<<<<<< .our
129
- BBB
130
-+=======
131
-+CCC
132
-+>>>>>>> .their
133
- AAA
134
- AAA
135
- AAA
136
-EXPECTED
137
-
119
git reset --hard initial &&
120
test_commit "change-a-b-mix-base" "ONE" "
121
AAA
@@ -159,6 +140,26 @@ AAA" &&
140
"$(sed -e "1{s/AAA/BBB/;}" -e "10{s/AAA/CCC/;}" <ONE)" &&
141
git merge-tree change-a-b-mix-base change-a-b-mix-A change-a-b-mix-B \
142
>actual &&
143
+
144
+ cat >expected <<EXPECTED &&
145
+changed in both
146
+ base 100644 $(git rev-parse change-a-b-mix-base:ONE) ONE
147
+ our 100644 $(git rev-parse change-a-b-mix-A:ONE ) ONE
148
+ their 100644 $(git rev-parse change-a-b-mix-B:ONE ) ONE
149
+@@ -7,7 +7,11 @@
150
+ AAA
151
+ AAA
152
+ AAA
153
++<<<<<<< .our
154
+ BBB
155
++=======
156
++CCC
157
++>>>>>>> .their
158
+ AAA
159
+ AAA
160
+ AAA
161
+EXPECTED
162
+
163
test_cmp expected actual
164
'
165
@@ -173,20 +174,20 @@ test_expect_success 'file remove A, !B' '
174
'
175
176
test_expect_success 'file remove !A, B' '
176
- cat >expected <<\EXPECTED &&
177
-removed in remote
178
- base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
179
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
180
-@@ -1 +0,0 @@
181
--AAA
182
-EXPECTED
183
-
177
git reset --hard initial &&
178
test_commit "rm-not-a-b-base" "ONE" "AAA" &&
179
git rm ONE &&
180
git commit -m "rm-not-a-b" &&
181
git tag "rm-not-a-b" &&
182
git merge-tree rm-a-not-b-base rm-a-not-b-base rm-a-not-b >actual &&
183
+ cat >expected <<EXPECTED &&
184
+removed in remote
185
+ base 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
186
+ our 100644 $(git rev-parse rm-a-not-b-base:ONE) ONE
187
+@@ -1 +0,0 @@
188
+-AAA
189
+EXPECTED
190
+
191
test_cmp expected actual
192
'
193
@@ -201,14 +202,6 @@ test_expect_success 'file remove A, B (same)' '
202
'
203
204
test_expect_success 'file change A, remove B' '
204
- cat >expected <<\EXPECTED &&
205
-removed in remote
206
- base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
207
- our 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
208
-@@ -1 +0,0 @@
209
--BBB
210
-EXPECTED
211
-
205
git reset --hard initial &&
206
test_commit "change-a-rm-b-base" "ONE" "AAA" &&
207
test_commit "change-a-rm-b-A" "ONE" "BBB" &&
@@ -218,16 +211,18 @@ EXPECTED
211
git tag "change-a-rm-b-B" &&
212
git merge-tree change-a-rm-b-base change-a-rm-b-A change-a-rm-b-B \
213
>actual &&
214
+ cat >expected <<EXPECTED &&
215
+removed in remote
216
+ base 100644 $(git rev-parse change-a-rm-b-base:ONE) ONE
217
+ our 100644 $(git rev-parse change-a-rm-b-A:ONE ) ONE
218
+@@ -1 +0,0 @@
219
+-BBB
220
+EXPECTED
221
+
222
test_cmp expected actual
223
'
224
225
test_expect_success 'file remove A, change B' '
225
- cat >expected <<\EXPECTED &&
226
-removed in local
227
- base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d ONE
228
- their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 ONE
229
-EXPECTED
230
-
226
git reset --hard initial &&
227
test_commit "rm-a-change-b-base" "ONE" "AAA" &&
228
@@ -238,6 +233,11 @@ EXPECTED
233
test_commit "rm-a-change-b-B" "ONE" "BBB" &&
234
git merge-tree rm-a-change-b-base rm-a-change-b-A rm-a-change-b-B \
235
>actual &&
236
+ cat >expected <<EXPECTED &&
237
+removed in local
238
+ base 100644 $(git rev-parse rm-a-change-b-base:ONE) ONE
239
+ their 100644 $(git rev-parse rm-a-change-b-B:ONE ) ONE
240
+EXPECTED
241
test_cmp expected actual
242
'
243
@@ -250,10 +250,17 @@ test_expect_success 'tree add A, B (same)' '
250
'
251
252
test_expect_success 'tree add A, B (different)' '
253
- cat >expect <<-\EOF &&
253
+ git reset --hard initial &&
254
+ mkdir sub &&
255
+ test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
256
+ git reset --hard initial &&
257
+ mkdir sub &&
258
+ test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
259
+ git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
260
+ cat >expect <<-EOF &&
261
added in both
255
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
256
- their 100644 ba629238ca89489f2b350e196ca445e09d8bb834 sub/file
262
+ our 100644 $(git rev-parse add-tree-a-b-A:sub/file) sub/file
263
+ their 100644 $(git rev-parse add-tree-a-b-B:sub/file) sub/file
264
@@ -1 +1,5 @@
265
+<<<<<<< .our
266
AAA
@@ -261,24 +268,10 @@ test_expect_success 'tree add A, B (different)' '
268
+BBB
269
+>>>>>>> .their
270
EOF
264
- git reset --hard initial &&
265
- mkdir sub &&
266
- test_commit "add sub/file" "sub/file" "AAA" add-tree-a-b-A &&
267
- git reset --hard initial &&
268
- mkdir sub &&
269
- test_commit "add sub/file" "sub/file" "BBB" add-tree-a-b-B &&
270
- git merge-tree initial add-tree-a-b-A add-tree-a-b-B >actual &&
271
test_cmp expect actual
272
'
273
274
test_expect_success 'tree unchanged A, removed B' '
275
- cat >expect <<-\EOF &&
276
- removed in remote
277
- base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
278
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d sub/file
279
- @@ -1 +0,0 @@
280
- -AAA
281
- EOF
275
git reset --hard initial &&
276
mkdir sub &&
277
test_commit "add sub/file" "sub/file" "AAA" tree-remove-b-initial &&
@@ -287,6 +280,13 @@ test_expect_success 'tree unchanged A, removed B' '
280
git commit -m "remove sub/file" &&
281
git tag tree-remove-b-B &&
282
git merge-tree tree-remove-b-initial tree-remove-b-initial tree-remove-b-B >actual &&
283
+ cat >expect <<-EOF &&
284
+ removed in remote
285
+ base 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
286
+ our 100644 $(git rev-parse tree-remove-b-initial:sub/file) sub/file
287
+ @@ -1 +0,0 @@
288
+ -AAA
289
+ EOF
290
test_cmp expect actual
291
'
292
@@ -296,14 +296,14 @@ test_expect_success 'turn file to tree' '
296
mkdir initial-file &&
297
test_commit "turn-file-to-tree" "initial-file/ONE" "CCC" &&
298
git merge-tree initial initial turn-file-to-tree >actual &&
299
- cat >expect <<-\EOF &&
299
+ cat >expect <<-EOF &&
300
added in remote
301
- their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 initial-file/ONE
301
+ their 100644 $(git rev-parse turn-file-to-tree:initial-file/ONE) initial-file/ONE
302
@@ -0,0 +1 @@
303
+CCC
304
removed in remote
305
- base 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
306
- our 100644 e79c5e8f964493290a409888d5413a737e8e5dd5 initial-file
305
+ base 100644 $(git rev-parse initial:initial-file) initial-file
306
+ our 100644 $(git rev-parse initial:initial-file) initial-file
307
@@ -1 +0,0 @@
308
-initial
309
EOF
@@ -318,14 +318,14 @@ test_expect_success 'turn tree to file' '
318
rm -fr dir &&
319
test_commit "make-file" "dir" "CCC" &&
320
git merge-tree add-tree add-another-tree make-file >actual &&
321
- cat >expect <<-\EOF &&
321
+ cat >expect <<-EOF &&
322
removed in remote
323
- base 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
324
- our 100644 43d5a8ed6ef6c00ff775008633f95787d088285d dir/path
323
+ base 100644 $(git rev-parse add-tree:dir/path) dir/path
324
+ our 100644 $(git rev-parse add-tree:dir/path) dir/path
325
@@ -1 +0,0 @@
326
-AAA
327
added in remote
328
- their 100644 43aa4fdec31eb92e1fdc2f0ce6ea9ddb7c32bcf7 dir
328
+ their 100644 $(git rev-parse make-file:dir) dir
329
@@ -0,0 +1 @@
330
+CCC
331
EOF