Skip to content

Commit dc0a13f

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a7e67c1 commit dc0a13f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

revision.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ static struct commit *handle_commit(struct rev_info *revs,
248248
if (!object) {
249249
if (revs->ignore_missing_links || (flags & UNINTERESTING))
250250
return NULL;
251+
if (revs->exclude_promisor_objects &&
252+
is_promisor_object(&tag->tagged->oid))
253+
return NULL;
251254
die("bad object %s", oid_to_hex(&tag->tagged->oid));
252255
}
253256
object->flags |= flags;

t/t5616-partial-clone.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,45 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
216216
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
217217
'
218218

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+
219258
stop_httpd
220259

221260
test_done

0 commit comments

Comments
 (0)