@@ -113,53 +113,54 @@ strlen () {
113
113
114
114
run_tests () {
115
115
type=$1
116
- oid= $2
116
+ object_name= " $2 "
117
117
size=$3
118
118
content=$4
119
119
pretty_content=$5
120
+ oid=${6:- " $object_name " }
120
121
121
122
batch_output=" $oid $type $size
122
123
$content "
123
124
124
125
test_expect_success " $type exists" '
125
- git cat-file -e $oid
126
+ git cat-file -e "$object_name"
126
127
'
127
128
128
129
test_expect_success " Type of $type is correct" '
129
130
echo $type >expect &&
130
- git cat-file -t $oid >actual &&
131
+ git cat-file -t "$object_name" >actual &&
131
132
test_cmp expect actual
132
133
'
133
134
134
135
test_expect_success " Size of $type is correct" '
135
136
echo $size >expect &&
136
- git cat-file -s $oid >actual &&
137
+ git cat-file -s "$object_name" >actual &&
137
138
test_cmp expect actual
138
139
'
139
140
140
141
test -z " $content " ||
141
142
test_expect_success " Content of $type is correct" '
142
143
echo_without_newline "$content" >expect &&
143
- git cat-file $type $oid >actual &&
144
+ git cat-file $type "$object_name" >actual &&
144
145
test_cmp expect actual
145
146
'
146
147
147
148
test_expect_success " Pretty content of $type is correct" '
148
149
echo_without_newline "$pretty_content" >expect &&
149
- git cat-file -p $oid >actual &&
150
+ git cat-file -p "$object_name" >actual &&
150
151
test_cmp expect actual
151
152
'
152
153
153
154
test -z " $content " ||
154
155
test_expect_success " --batch output of $type is correct" '
155
156
echo "$batch_output" >expect &&
156
- echo $oid | git cat-file --batch >actual &&
157
+ echo "$object_name" | git cat-file --batch >actual &&
157
158
test_cmp expect actual
158
159
'
159
160
160
161
test_expect_success " --batch-check output of $type is correct" '
161
162
echo "$oid $type $size" >expect &&
162
- echo_without_newline $oid | git cat-file --batch-check >actual &&
163
+ echo_without_newline "$object_name" | git cat-file --batch-check >actual &&
163
164
test_cmp expect actual
164
165
'
165
166
@@ -168,33 +169,42 @@ $content"
168
169
test -z " $content " ||
169
170
test_expect_success " --batch-command $opt output of $type content is correct" '
170
171
echo "$batch_output" >expect &&
171
- test_write_lines "contents $oid " | git cat-file --batch-command $opt >actual &&
172
+ test_write_lines "contents $object_name " | git cat-file --batch-command $opt >actual &&
172
173
test_cmp expect actual
173
174
'
174
175
175
176
test_expect_success " --batch-command $opt output of $type info is correct" '
176
177
echo "$oid $type $size" >expect &&
177
- test_write_lines "info $oid " |
178
+ test_write_lines "info $object_name " |
178
179
git cat-file --batch-command $opt >actual &&
179
180
test_cmp expect actual
180
181
'
181
182
done
182
183
183
184
test_expect_success " custom --batch-check format" '
184
185
echo "$type $oid" >expect &&
185
- echo $oid | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
186
+ echo "$object_name" | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
186
187
test_cmp expect actual
187
188
'
188
189
189
190
test_expect_success " custom --batch-command format" '
190
191
echo "$type $oid" >expect &&
191
- echo "info $oid " | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
192
+ echo "info $object_name " | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
192
193
test_cmp expect actual
193
194
'
194
195
195
- test_expect_success ' --batch-check with %(rest)' '
196
+ # FIXME: %(rest) is incompatible with object names that include whitespace,
197
+ # e.g. HEAD:path/to/a/file with spaces. Use the resolved OID as input to
198
+ # test this instead of the raw object name.
199
+ if echo " $object_name " | grep " " ; then
200
+ test_rest=test_expect_failure
201
+ else
202
+ test_rest=test_expect_success
203
+ fi
204
+
205
+ $test_rest ' --batch-check with %(rest)' '
196
206
echo "$type this is some extra content" >expect &&
197
- echo "$oid this is some extra content" |
207
+ echo "$object_name this is some extra content" |
198
208
git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
199
209
test_cmp expect actual
200
210
'
@@ -205,7 +215,7 @@ $content"
205
215
echo "$size" &&
206
216
echo "$content"
207
217
} >expect &&
208
- echo $oid | git cat-file --batch="%(objectsize)" >actual &&
218
+ echo "$object_name" | git cat-file --batch="%(objectsize)" >actual &&
209
219
test_cmp expect actual
210
220
'
211
221
@@ -215,7 +225,7 @@ $content"
215
225
echo "$type" &&
216
226
echo "$content"
217
227
} >expect &&
218
- echo $oid | git cat-file --batch="%(objecttype)" >actual &&
228
+ echo "$object_name" | git cat-file --batch="%(objecttype)" >actual &&
219
229
test_cmp expect actual
220
230
'
221
231
}
@@ -230,6 +240,8 @@ test_expect_success "setup" '
230
240
git config extensions.compatobjectformat $test_compat_hash_algo &&
231
241
echo_without_newline "$hello_content" > hello &&
232
242
git update-index --add hello &&
243
+ echo_without_newline "$hello_content" > "path with spaces" &&
244
+ git update-index --add --chmod=+x "path with spaces" &&
233
245
git commit -m "add hello file"
234
246
'
235
247
@@ -269,13 +281,17 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
269
281
270
282
tree_oid=$( git write-tree)
271
283
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} "
284
+ tree_size=$(( 2 * $(test_oid rawsz) + 13 + 24 ))
285
+ tree_compat_size=$(( 2 * $(test_oid -- hash= compat rawsz) + 13 + 24 ))
286
+ tree_pretty_content=" 100644 blob $hello_oid hello${LF} 100755 blob $hello_oid path with spaces ${LF} "
287
+ tree_compat_pretty_content=" 100644 blob $hello_compat_oid hello${LF} 100755 blob $hello_compat_oid path with spaces ${LF} "
276
288
277
289
run_tests ' tree' $tree_oid $tree_size " " " $tree_pretty_content "
278
290
run_tests ' tree' $tree_compat_oid $tree_compat_size " " " $tree_compat_pretty_content "
291
+ run_tests ' blob' " $tree_oid :hello" $hello_size " " " $hello_content " $hello_oid
292
+ run_tests ' blob' " $tree_compat_oid :hello" $hello_size " " " $hello_content " $hello_compat_oid
293
+ run_tests ' blob' " $tree_oid :path with spaces" $hello_size " " " $hello_content " $hello_oid
294
+ run_tests ' blob' " $tree_compat_oid :path with spaces" $hello_size " " " $hello_content " $hello_compat_oid
279
295
280
296
commit_message=" Initial commit"
281
297
commit_oid=$( echo_without_newline " $commit_message " | git commit-tree $tree_oid )
0 commit comments