@@ -113,53 +113,55 @@ strlen () {
113
113
114
114
run_tests () {
115
115
type=$1
116
- oid=$2
117
- size=$3
118
- content=$4
119
- pretty_content=$5
116
+ object_name=" $2 "
117
+ mode=$3
118
+ size=$4
119
+ content=$5
120
+ pretty_content=$6
121
+ oid=${7:- " $object_name " }
120
122
121
123
batch_output=" $oid $type $size
122
124
$content "
123
125
124
126
test_expect_success " $type exists" '
125
- git cat-file -e $oid
127
+ git cat-file -e "$object_name"
126
128
'
127
129
128
130
test_expect_success " Type of $type is correct" '
129
131
echo $type >expect &&
130
- git cat-file -t $oid >actual &&
132
+ git cat-file -t "$object_name" >actual &&
131
133
test_cmp expect actual
132
134
'
133
135
134
136
test_expect_success " Size of $type is correct" '
135
137
echo $size >expect &&
136
- git cat-file -s $oid >actual &&
138
+ git cat-file -s "$object_name" >actual &&
137
139
test_cmp expect actual
138
140
'
139
141
140
142
test -z " $content " ||
141
143
test_expect_success " Content of $type is correct" '
142
144
echo_without_newline "$content" >expect &&
143
- git cat-file $type $oid >actual &&
145
+ git cat-file $type "$object_name" >actual &&
144
146
test_cmp expect actual
145
147
'
146
148
147
149
test_expect_success " Pretty content of $type is correct" '
148
150
echo_without_newline "$pretty_content" >expect &&
149
- git cat-file -p $oid >actual &&
151
+ git cat-file -p "$object_name" >actual &&
150
152
test_cmp expect actual
151
153
'
152
154
153
155
test -z " $content " ||
154
156
test_expect_success " --batch output of $type is correct" '
155
157
echo "$batch_output" >expect &&
156
- echo $oid | git cat-file --batch >actual &&
158
+ echo "$object_name" | git cat-file --batch >actual &&
157
159
test_cmp expect actual
158
160
'
159
161
160
162
test_expect_success " --batch-check output of $type is correct" '
161
163
echo "$oid $type $size" >expect &&
162
- echo_without_newline $oid | git cat-file --batch-check >actual &&
164
+ echo_without_newline "$object_name" | git cat-file --batch-check >actual &&
163
165
test_cmp expect actual
164
166
'
165
167
@@ -168,44 +170,59 @@ $content"
168
170
test -z " $content " ||
169
171
test_expect_success " --batch-command $opt output of $type content is correct" '
170
172
echo "$batch_output" >expect &&
171
- test_write_lines "contents $oid " | git cat-file --batch-command $opt >actual &&
173
+ test_write_lines "contents $object_name " | git cat-file --batch-command $opt >actual &&
172
174
test_cmp expect actual
173
175
'
174
176
175
177
test_expect_success " --batch-command $opt output of $type info is correct" '
176
178
echo "$oid $type $size" >expect &&
177
- test_write_lines "info $oid " |
179
+ test_write_lines "info $object_name " |
178
180
git cat-file --batch-command $opt >actual &&
179
181
test_cmp expect actual
180
182
'
181
183
done
182
184
183
185
test_expect_success " custom --batch-check format" '
184
186
echo "$type $oid" >expect &&
185
- echo $oid | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
187
+ echo "$object_name" | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
186
188
test_cmp expect actual
187
189
'
188
190
189
191
test_expect_success " custom --batch-command format" '
190
192
echo "$type $oid" >expect &&
191
- echo "info $oid " | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
193
+ echo "info $object_name " | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
192
194
test_cmp expect actual
193
195
'
194
196
195
- test_expect_success ' --batch-check with %(rest)' '
197
+ # FIXME: %(rest) is incompatible with object names that include whitespace,
198
+ # e.g. HEAD:path/to/a/file with spaces. Use the resolved OID as input to
199
+ # test this instead of the raw object name.
200
+ if echo " $object_name " | grep " " ; then
201
+ test_rest=test_expect_failure
202
+ else
203
+ test_rest=test_expect_success
204
+ fi
205
+
206
+ $test_rest ' --batch-check with %(rest)' '
196
207
echo "$type this is some extra content" >expect &&
197
- echo "$oid this is some extra content" |
208
+ echo "$object_name this is some extra content" |
198
209
git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
199
210
test_cmp expect actual
200
211
'
201
212
213
+ test_expect_success ' --batch-check with %(objectmode)' '
214
+ echo "$mode $oid" >expect &&
215
+ echo $object_name | git cat-file --batch-check="%(objectmode) %(objectname)" >actual &&
216
+ test_cmp expect actual
217
+ '
218
+
202
219
test -z " $content " ||
203
220
test_expect_success " --batch without type ($type )" '
204
221
{
205
222
echo "$size" &&
206
223
echo "$content"
207
224
} >expect &&
208
- echo $oid | git cat-file --batch="%(objectsize)" >actual &&
225
+ echo "$object_name" | git cat-file --batch="%(objectsize)" >actual &&
209
226
test_cmp expect actual
210
227
'
211
228
@@ -215,7 +232,7 @@ $content"
215
232
echo "$type" &&
216
233
echo "$content"
217
234
} >expect &&
218
- echo $oid | git cat-file --batch="%(objecttype)" >actual &&
235
+ echo "$object_name" | git cat-file --batch="%(objecttype)" >actual &&
219
236
test_cmp expect actual
220
237
'
221
238
}
@@ -230,13 +247,14 @@ test_expect_success "setup" '
230
247
git config extensions.compatobjectformat $test_compat_hash_algo &&
231
248
echo_without_newline "$hello_content" > hello &&
232
249
git update-index --add hello &&
250
+ echo_without_newline "$hello_content" > "path with spaces" &&
251
+ git update-index --add --chmod=+x "path with spaces" &&
233
252
git commit -m "add hello file"
234
253
'
235
254
236
255
run_blob_tests () {
237
256
oid=$1
238
-
239
- run_tests ' blob' $oid $hello_size " $hello_content " " $hello_content "
257
+ run_tests ' blob' $oid " " $hello_size " $hello_content " " $hello_content "
240
258
241
259
test_expect_success ' --batch-command --buffer with flush for blob info' '
242
260
echo "$oid blob $hello_size" >expect &&
@@ -269,13 +287,17 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
269
287
270
288
tree_oid=$( git write-tree)
271
289
tree_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid )
272
- tree_size=$(( $(test_oid rawsz) + 13 ))
273
- tree_compat_size=$(( $(test_oid -- hash= compat rawsz) + 13 ))
274
- tree_pretty_content=" 100644 blob $hello_oid hello${LF} "
275
- tree_compat_pretty_content=" 100644 blob $hello_compat_oid hello${LF} "
276
-
277
- run_tests ' tree' $tree_oid $tree_size " " " $tree_pretty_content "
278
- run_tests ' tree' $tree_compat_oid $tree_compat_size " " " $tree_compat_pretty_content "
290
+ tree_size=$(( 2 * $(test_oid rawsz) + 13 + 24 ))
291
+ tree_compat_size=$(( 2 * $(test_oid -- hash= compat rawsz) + 13 + 24 ))
292
+ tree_pretty_content=" 100644 blob $hello_oid hello${LF} 100755 blob $hello_oid path with spaces${LF} "
293
+ tree_compat_pretty_content=" 100644 blob $hello_compat_oid hello${LF} 100755 blob $hello_compat_oid path with spaces${LF} "
294
+
295
+ run_tests ' tree' $tree_oid " " $tree_size " " " $tree_pretty_content "
296
+ run_tests ' tree' $tree_compat_oid " " $tree_compat_size " " " $tree_compat_pretty_content "
297
+ run_tests ' blob' " $tree_oid :hello" " 100644" $hello_size " " " $hello_content " $hello_oid
298
+ run_tests ' blob' " $tree_compat_oid :hello" " 100644" $hello_size " " " $hello_content " $hello_compat_oid
299
+ run_tests ' blob' " $tree_oid :path with spaces" " 100755" $hello_size " " " $hello_content " $hello_oid
300
+ run_tests ' blob' " $tree_compat_oid :path with spaces" " 100755" $hello_size " " " $hello_content " $hello_compat_oid
279
301
280
302
commit_message=" Initial commit"
281
303
commit_oid=$( echo_without_newline " $commit_message " | git commit-tree $tree_oid )
@@ -294,8 +316,8 @@ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
294
316
295
317
$commit_message "
296
318
297
- run_tests ' commit' $commit_oid $commit_size " $commit_content " " $commit_content "
298
- run_tests ' commit' $commit_compat_oid $commit_compat_size " $commit_compat_content " " $commit_compat_content "
319
+ run_tests ' commit' $commit_oid " " $commit_size " $commit_content " " $commit_content "
320
+ run_tests ' commit' $commit_compat_oid " " $commit_compat_size " $commit_compat_content " " $commit_compat_content "
299
321
300
322
tag_header_without_oid=" type blob
301
323
tag hellotag
@@ -318,8 +340,8 @@ tag_size=$(strlen "$tag_content")
318
340
tag_compat_oid=$( git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid )
319
341
tag_compat_size=$( strlen " $tag_compat_content " )
320
342
321
- run_tests ' tag' $tag_oid $tag_size " $tag_content " " $tag_content "
322
- run_tests ' tag' $tag_compat_oid $tag_compat_size " $tag_compat_content " " $tag_compat_content "
343
+ run_tests ' tag' $tag_oid " " $tag_size " $tag_content " " $tag_content "
344
+ run_tests ' tag' $tag_compat_oid " " $tag_compat_size " $tag_compat_content " " $tag_compat_content "
323
345
324
346
test_expect_success " Reach a blob from a tag pointing to it" '
325
347
echo_without_newline "$hello_content" >expect &&
@@ -1198,6 +1220,31 @@ test_expect_success 'cat-file --batch-check respects replace objects' '
1198
1220
test_cmp expect actual
1199
1221
'
1200
1222
1223
+ test_expect_success ' batch-check with a submodule' '
1224
+ # FIXME: this call to mktree is incompatible with compatObjectFormat
1225
+ # because the submodule OID cannot be mapped to the compat hash algo.
1226
+ test_unconfig extensions.compatobjectformat &&
1227
+ printf "160000 commit $(test_oid deadbeef)\tsub\n" >tree-with-sub &&
1228
+ tree=$(git mktree <tree-with-sub) &&
1229
+ test_config extensions.compatobjectformat $test_compat_hash_algo &&
1230
+
1231
+ git cat-file --batch-check >actual <<-EOF &&
1232
+ $tree:sub
1233
+ EOF
1234
+ printf "$(test_oid deadbeef) submodule\n" >expect &&
1235
+ test_cmp expect actual
1236
+ '
1237
+
1238
+ test_expect_success ' batch-check with a submodule, object exists' '
1239
+ printf "160000 commit $commit_oid\tsub\n" >tree-with-sub &&
1240
+ tree=$(git mktree <tree-with-sub) &&
1241
+ git cat-file --batch-check >actual <<-EOF &&
1242
+ $tree:sub
1243
+ EOF
1244
+ printf "$commit_oid commit $commit_size\n" >expect &&
1245
+ test_cmp expect actual
1246
+ '
1247
+
1201
1248
# Pull the entry for object with oid "$1" out of the output of
1202
1249
# "cat-file --batch", including its object content (which requires
1203
1250
# parsing and reading a set amount of bytes, hence perl).
0 commit comments