@@ -216,6 +216,50 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
216
216
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
217
217
'
218
218
219
+ test_expect_success ' when partial cloning, tolerate server not sending target of tag' '
220
+ SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
221
+ rm -rf "$SERVER" repo &&
222
+ test_create_repo "$SERVER" &&
223
+ test_commit -C "$SERVER" foo &&
224
+ test_config -C "$SERVER" uploadpack.allowfilter 1 &&
225
+ test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
226
+
227
+ # Create an annotated tag pointing to a blob.
228
+ BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
229
+ git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
230
+
231
+ # Craft a packfile including the tag, but not the blob it points to.
232
+ # Also, omit objects referenced from HEAD in order to force a second
233
+ # fetch (to fetch missing objects) upon the automatic checkout that
234
+ # happens after a clone.
235
+ printf "%s\n%s\n--not\n%s\n%s\n" \
236
+ $(git -C "$SERVER" rev-parse HEAD) \
237
+ $(git -C "$SERVER" rev-parse myblob) \
238
+ $(git -C "$SERVER" rev-parse HEAD^{tree}) \
239
+ $(git -C "$SERVER" rev-parse myblob^{blob}) |
240
+ git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
241
+
242
+ # Replace the existing packfile with the crafted one. The protocol
243
+ # requires that the packfile be sent in sideband 1, hence the extra
244
+ # \x01 byte at the beginning.
245
+ printf "1,/packfile/!c %04x\\\\x01%s0000" \
246
+ "$(($(wc -c <incomplete.pack) + 5))" \
247
+ "$(sed_escape <incomplete.pack)" \
248
+ >"$HTTPD_ROOT_PATH/one-time-sed" &&
249
+
250
+ # Use protocol v2 because the sed command looks for the "packfile"
251
+ # section header.
252
+ test_config -C "$SERVER" protocol.version 2 &&
253
+
254
+ # Exercise to make sure it works.
255
+ git -c protocol.version=2 clone \
256
+ --filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
257
+ ! grep "missing object referenced by" err &&
258
+
259
+ # Ensure that the one-time-sed script was used.
260
+ ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
261
+ '
262
+
219
263
stop_httpd
220
264
221
265
test_done
0 commit comments