revision: tolerate promised targets of tags

In handle_commit(), it is fatal for an annotated tag to point to a non-existent object. --exclude-promisor-objects should relax this rule and allow non-existent objects that are promisor objects, but this is not the case. Update handle_commit() to tolerate this situation. This was observed when cloning from a repository with an annotated tag pointing to a blob. The test included in this patch demonstrates this case. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jul 12, 2018 at 17:03 UTC dc0a13f6813f35bae5fd2de6af4d5524a20d5b82
2 files changed +42
revision.c
+3
@@ -248,6 +248,9 @@ static struct commit *handle_commit(struct rev_info *revs,
248 if (!object) {
249 if (revs->ignore_missing_links || (flags & UNINTERESTING))
250 return NULL;
251 + if (revs->exclude_promisor_objects &&
252 + is_promisor_object(&tag->tagged->oid))
253 + return NULL;
254 die("bad object %s", oid_to_hex(&tag->tagged->oid));
255 }
256 object->flags |= flags;
t/t5616-partial-clone.sh
+39
@@ -216,6 +216,45 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
216 ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
217 '
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 + printf "%s\n%s\n--not\n%s\n" \
233 + $(git -C "$SERVER" rev-parse HEAD) \
234 + $(git -C "$SERVER" rev-parse myblob) \
235 + $(git -C "$SERVER" rev-parse myblob^{blob}) |
236 + git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
237 +
238 + # Replace the existing packfile with the crafted one. The protocol
239 + # requires that the packfile be sent in sideband 1, hence the extra
240 + # \x01 byte at the beginning.
241 + printf "1,/packfile/!c %04x\\\\x01%s0000" \
242 + "$(($(wc -c <incomplete.pack) + 5))" \
243 + "$(sed_escape <incomplete.pack)" \
244 + >"$HTTPD_ROOT_PATH/one-time-sed" &&
245 +
246 + # Use protocol v2 because the sed command looks for the "packfile"
247 + # section header.
248 + test_config -C "$SERVER" protocol.version 2 &&
249 +
250 + # Exercise to make sure it works.
251 + git -c protocol.version=2 clone \
252 + --filter=blob:none $HTTPD_URL/one_time_sed/server repo &&
253 +
254 + # Ensure that the one-time-sed script was used.
255 + ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
256 +'
257 +
258 stop_httpd
259
260 test_done