Skip to content

Commit 8c4cc32

Browse files
jonathantanmygitster
authored andcommitted
tag: don't warn if target is missing but promised
deref_tag() prints a warning if the object that a tag refers to does not exist. However, when a partial clone has an annotated tag from its promisor remote, but not the object that it refers to, printing a warning on such a tag is incorrect. This occurs, for example, when the checkout that happens after a partial clone causes some objects to be fetched - and as part of the fetch, all local refs are read. The test included in this patch demonstrates this situation. Therefore, do not print a warning in this case. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc0a13f commit 8c4cc32

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

t/t5616-partial-clone.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,13 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
229229
git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
230230
231231
# Craft a packfile including the tag, but not the blob it points to.
232-
printf "%s\n%s\n--not\n%s\n" \
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" \
233236
$(git -C "$SERVER" rev-parse HEAD) \
234237
$(git -C "$SERVER" rev-parse myblob) \
238+
$(git -C "$SERVER" rev-parse HEAD^{tree}) \
235239
$(git -C "$SERVER" rev-parse myblob^{blob}) |
236240
git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
237241
@@ -249,7 +253,8 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
249253
250254
# Exercise to make sure it works.
251255
git -c protocol.version=2 clone \
252-
--filter=blob:none $HTTPD_URL/one_time_sed/server repo &&
256+
--filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
257+
! grep "missing object referenced by" err &&
253258
254259
# Ensure that the one-time-sed script was used.
255260
! test -e "$HTTPD_ROOT_PATH/one-time-sed"

tag.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "tree.h"
55
#include "blob.h"
66
#include "gpg-interface.h"
7+
#include "packfile.h"
78

89
const char *tag_type = "tag";
910

@@ -64,12 +65,18 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
6465

6566
struct object *deref_tag(struct object *o, const char *warn, int warnlen)
6667
{
68+
struct object_id *last_oid = NULL;
6769
while (o && o->type == OBJ_TAG)
68-
if (((struct tag *)o)->tagged)
69-
o = parse_object(&((struct tag *)o)->tagged->oid);
70-
else
70+
if (((struct tag *)o)->tagged) {
71+
last_oid = &((struct tag *)o)->tagged->oid;
72+
o = parse_object(last_oid);
73+
} else {
74+
last_oid = NULL;
7175
o = NULL;
76+
}
7277
if (!o && warn) {
78+
if (last_oid && is_promisor_object(last_oid))
79+
return NULL;
7380
if (!warnlen)
7481
warnlen = strlen(warn);
7582
error("missing object referenced by '%.*s'", warnlen, warn);

0 commit comments

Comments
 (0)