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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 17, 2022 at 14:04 UTC
62091b4c87a199c172556f15c5662c6c3679e9cd
2 files changed
+19
-11
builtin/fetch.c
+18
-8
@@ -1495,12 +1495,12 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
1495
return transport;
1496
}
1497
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)
1502
{
1503
- int cannot_reuse;
1503
+ int retcode, cannot_reuse;
1504
1505
/*
1506
* Once we have set TRANS_OPT_DEEPEN_SINCE, we can't unset it
@@ -1519,12 +1519,14 @@ static void backfill_tags(struct transport *transport,
1519
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
1520
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
1521
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);
1523
1524
if (gsecondary) {
1525
transport_disconnect(gsecondary);
1526
gsecondary = NULL;
1527
}
1528
+
1529
+ return retcode;
1530
}
1531
1532
static int do_fetch(struct transport *transport,
@@ -1632,8 +1634,16 @@ static int do_fetch(struct transport *transport,
1634
struct ref *tags_ref_map = NULL, **tail = &tags_ref_map;
1635
1636
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
+ }
1647
1648
free_refs(tags_ref_map);
1649
}
t/t5503-tagfollow.sh
+1
-3
@@ -233,9 +233,7 @@ test_expect_success 'backfill failure causes command to fail' '
233
done
234
EOF
235
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 &&
237
test $B = $(git -C clone5 rev-parse --verify refs/heads/something) &&
238
test $S = $(git -C clone5 rev-parse --verify tag2) &&
239
test_must_fail git -C clone5 rev-parse --verify tag1