@@ -113,53 +113,54 @@ strlen () {
113113
114114run_tests () {
115115 type=$1
116- oid= $2
116+ object_name= " $2 "
117117 size=$3
118118 content=$4
119119 pretty_content=$5
120+ oid=${6:- " $object_name " }
120121
121122 batch_output=" $oid $type $size
122123$content "
123124
124125 test_expect_success " $type exists" '
125- git cat-file -e $oid
126+ git cat-file -e "$object_name"
126127 '
127128
128129 test_expect_success " Type of $type is correct" '
129130 echo $type >expect &&
130- git cat-file -t $oid >actual &&
131+ git cat-file -t "$object_name" >actual &&
131132 test_cmp expect actual
132133 '
133134
134135 test_expect_success " Size of $type is correct" '
135136 echo $size >expect &&
136- git cat-file -s $oid >actual &&
137+ git cat-file -s "$object_name" >actual &&
137138 test_cmp expect actual
138139 '
139140
140141 test -z " $content " ||
141142 test_expect_success " Content of $type is correct" '
142143 echo_without_newline "$content" >expect &&
143- git cat-file $type $oid >actual &&
144+ git cat-file $type "$object_name" >actual &&
144145 test_cmp expect actual
145146 '
146147
147148 test_expect_success " Pretty content of $type is correct" '
148149 echo_without_newline "$pretty_content" >expect &&
149- git cat-file -p $oid >actual &&
150+ git cat-file -p "$object_name" >actual &&
150151 test_cmp expect actual
151152 '
152153
153154 test -z " $content " ||
154155 test_expect_success " --batch output of $type is correct" '
155156 echo "$batch_output" >expect &&
156- echo $oid | git cat-file --batch >actual &&
157+ echo "$object_name" | git cat-file --batch >actual &&
157158 test_cmp expect actual
158159 '
159160
160161 test_expect_success " --batch-check output of $type is correct" '
161162 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 &&
163164 test_cmp expect actual
164165 '
165166
@@ -168,33 +169,42 @@ $content"
168169 test -z " $content " ||
169170 test_expect_success " --batch-command $opt output of $type content is correct" '
170171 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 &&
172173 test_cmp expect actual
173174 '
174175
175176 test_expect_success " --batch-command $opt output of $type info is correct" '
176177 echo "$oid $type $size" >expect &&
177- test_write_lines "info $oid " |
178+ test_write_lines "info $object_name " |
178179 git cat-file --batch-command $opt >actual &&
179180 test_cmp expect actual
180181 '
181182 done
182183
183184 test_expect_success " custom --batch-check format" '
184185 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 &&
186187 test_cmp expect actual
187188 '
188189
189190 test_expect_success " custom --batch-command format" '
190191 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 &&
192193 test_cmp expect actual
193194 '
194195
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)' '
196206 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" |
198208 git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
199209 test_cmp expect actual
200210 '
@@ -205,7 +215,7 @@ $content"
205215 echo "$size" &&
206216 echo "$content"
207217 } >expect &&
208- echo $oid | git cat-file --batch="%(objectsize)" >actual &&
218+ echo "$object_name" | git cat-file --batch="%(objectsize)" >actual &&
209219 test_cmp expect actual
210220 '
211221
@@ -215,7 +225,7 @@ $content"
215225 echo "$type" &&
216226 echo "$content"
217227 } >expect &&
218- echo $oid | git cat-file --batch="%(objecttype)" >actual &&
228+ echo "$object_name" | git cat-file --batch="%(objecttype)" >actual &&
219229 test_cmp expect actual
220230 '
221231}
@@ -230,6 +240,8 @@ test_expect_success "setup" '
230240 git config extensions.compatobjectformat $test_compat_hash_algo &&
231241 echo_without_newline "$hello_content" > hello &&
232242 git update-index --add hello &&
243+ echo_without_newline "$hello_content" > "path with spaces" &&
244+ git update-index --add --chmod=+x "path with spaces" &&
233245 git commit -m "add hello file"
234246'
235247
@@ -269,13 +281,17 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
269281
270282tree_oid=$( git write-tree)
271283tree_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} "
276288
277289run_tests ' tree' $tree_oid $tree_size " " " $tree_pretty_content "
278290run_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
279295
280296commit_message=" Initial commit"
281297commit_oid=$( echo_without_newline " $commit_message " | git commit-tree $tree_oid )
0 commit comments