Skip to content

Commit 62091b4

Browse files
pks-tgitster
authored andcommitted
fetch: report errors when backfilling tags fails
When the backfilling of tags fails we do not report this error to the caller, but only report it implicitly at a later point when reporting updated references. This leaves callers unable to act upon the information of whether the backfilling succeeded or not. Refactor the function to return an error code and pass it up the callstack. This causes us to correctly propagate the error back to the user of git-fetch(1). Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2983cec commit 62091b4

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

builtin/fetch.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,12 +1495,12 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
14951495
return transport;
14961496
}
14971497

1498-
static void backfill_tags(struct transport *transport,
1499-
struct ref *ref_map,
1500-
struct fetch_head *fetch_head,
1501-
struct worktree **worktrees)
1498+
static int backfill_tags(struct transport *transport,
1499+
struct ref *ref_map,
1500+
struct fetch_head *fetch_head,
1501+
struct worktree **worktrees)
15021502
{
1503-
int cannot_reuse;
1503+
int retcode, cannot_reuse;
15041504

15051505
/*
15061506
* Once we have set TRANS_OPT_DEEPEN_SINCE, we can't unset it
@@ -1519,12 +1519,14 @@ static void backfill_tags(struct transport *transport,
15191519
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
15201520
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
15211521
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
1522-
fetch_and_consume_refs(transport, ref_map, fetch_head, worktrees);
1522+
retcode = fetch_and_consume_refs(transport, ref_map, fetch_head, worktrees);
15231523

15241524
if (gsecondary) {
15251525
transport_disconnect(gsecondary);
15261526
gsecondary = NULL;
15271527
}
1528+
1529+
return retcode;
15281530
}
15291531

15301532
static int do_fetch(struct transport *transport,
@@ -1632,8 +1634,16 @@ static int do_fetch(struct transport *transport,
16321634
struct ref *tags_ref_map = NULL, **tail = &tags_ref_map;
16331635

16341636
find_non_local_tags(remote_refs, &tags_ref_map, &tail);
1635-
if (tags_ref_map)
1636-
backfill_tags(transport, tags_ref_map, &fetch_head, worktrees);
1637+
if (tags_ref_map) {
1638+
/*
1639+
* If backfilling of tags fails then we want to tell
1640+
* the user so, but we have to continue regardless to
1641+
* populate upstream information of the references we
1642+
* have already fetched above.
1643+
*/
1644+
if (backfill_tags(transport, tags_ref_map, &fetch_head, worktrees))
1645+
retcode = 1;
1646+
}
16371647

16381648
free_refs(tags_ref_map);
16391649
}

t/t5503-tagfollow.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ test_expect_success 'backfill failure causes command to fail' '
233233
done
234234
EOF
235235
236-
# Even though we fail to create refs/tags/tag1 the below command
237-
# unexpectedly succeeds.
238-
git -C clone5 fetch .. $B:refs/heads/something &&
236+
test_must_fail git -C clone5 fetch .. $B:refs/heads/something &&
239237
test $B = $(git -C clone5 rev-parse --verify refs/heads/something) &&
240238
test $S = $(git -C clone5 rev-parse --verify tag2) &&
241239
test_must_fail git -C clone5 rev-parse --verify tag1

0 commit comments

Comments
 (0)