From patchwork Fri Feb 11 07:46:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12742984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163A2C433F5 for ; Fri, 11 Feb 2022 07:47:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347814AbiBKHrG (ORCPT ); Fri, 11 Feb 2022 02:47:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347487AbiBKHrD (ORCPT ); Fri, 11 Feb 2022 02:47:03 -0500 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573C9B38 for ; Thu, 10 Feb 2022 23:47:03 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 9D93A3201D9C for ; Fri, 11 Feb 2022 02:47:02 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 11 Feb 2022 02:47:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; bh=BMZ9o2dZnbMjLW+unbLzORyXeZALgaOiIEgHYL rSM0E=; b=VEY8+hzUfA8nzGN/kzqLoBbovgwOsjpsrSeiw+cfrOdDqU9HJCNneN fOoSq31vjMo/MqOwT614cdDQtQu9u3B85OQLwtz7XXvofO65i9lhosneGNmPVfhu fCOizxB6sM6mG0uqSQ6Imc80mngv1p99xBUGtqujnkvquKLWszYUl3kHHEMAyDyW LPbq4cp+DU6V2uBlfhIOSMZ+GceI2OKhRmaupq58AURDhkpLfBR98QOo01tmvzRU 0WZriDFi5La1ujQM+ivqufftG1MZVjesxjD39FLAFd7sUaUxmtpFSNZCLFM4IRA1 yNPhuOjm6/NMvHFKdNDBsfpMzWH0duNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=BMZ9o2dZnbMjLW+un bLzORyXeZALgaOiIEgHYLrSM0E=; b=McvJPbXiBwwh/9ZjeKbg2RRJZ6qdeVcvz YkV9wsHmUS2DJoIB03RZc3eI+GWUEnKVmyZvnj6b9v1kzQbBkyjwGjJrD2MIu8DB 0+4jULcnPE9jxGBcn7lQNK9lhMIhlPQXQANdYm6FU3OWlAGpTxBfC+1zdB6/9S4l FJA6T8JVQ1GfZz44toUpPexU1T0kJ7V2Hw/VIZvtK6sRE1hiCtZGnYIeskRfiV2W /onT2x7NJDTZcV6KGUdN+8HQkTsjMmyzJOpCKf1V61zL6izMT435333UbW3WbOxw SQfyyS59pmCNUp7eN23ShFm7hhtQX8z0ZPcRKSk2+o+zGRT+PTWog== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddriedvgddutdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 11 Feb 2022 02:47:01 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 10438711 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 11 Feb 2022 07:47:00 +0000 (UTC) Date: Fri, 11 Feb 2022 08:46:59 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 4/6] fetch: report errors when backfilling tags fails Message-ID: <54fdee845bea7f67f46817417f8e5a504bd39665.1644565025.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- builtin/fetch.c | 29 +++++++++++++++++++++-------- t/t5503-tagfollow.sh | 4 +--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 627847e2f8..1eda0b68ff 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1495,12 +1495,12 @@ static struct transport *prepare_transport(struct remote *remote, int deepen) return transport; } -static void backfill_tags(struct transport *transport, - struct ref *ref_map, - struct fetch_head *fetch_head, - struct worktree **worktrees) +static int backfill_tags(struct transport *transport, + struct ref *ref_map, + struct fetch_head *fetch_head, + struct worktree **worktrees) { - int cannot_reuse; + int retcode, cannot_reuse; /* * Once we have set TRANS_OPT_DEEPEN_SINCE, we can't unset it @@ -1519,12 +1519,14 @@ static void backfill_tags(struct transport *transport, transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL); transport_set_option(transport, TRANS_OPT_DEPTH, "0"); transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL); - fetch_and_consume_refs(transport, ref_map, fetch_head, worktrees); + retcode = fetch_and_consume_refs(transport, ref_map, fetch_head, worktrees); if (gsecondary) { transport_disconnect(gsecondary); gsecondary = NULL; } + + return retcode; } static int do_fetch(struct transport *transport, @@ -1628,8 +1630,19 @@ static int do_fetch(struct transport *transport, struct ref *tags_ref_map = NULL, **tail = &tags_ref_map; find_non_local_tags(remote_refs, &tags_ref_map, &tail); - if (tags_ref_map) - backfill_tags(transport, tags_ref_map, &fetch_head, worktrees); + if (tags_ref_map) { + /* + * If backfilling tags succeeds we used to not return + * an error code to the user at all. Instead, we + * silently swallowed that error and updated the local + * state of the repository. We now notify the user of + * any such errors, but we continue to make sure that + * FETCH_HEAD and the upstream branch are configured as + * expected. + */ + if (backfill_tags(transport, tags_ref_map, &fetch_head, worktrees)) + retcode = 1; + } free_refs(tags_ref_map); } diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh index 888305ad4d..549f908b90 100755 --- a/t/t5503-tagfollow.sh +++ b/t/t5503-tagfollow.sh @@ -237,9 +237,7 @@ test_expect_success 'backfill failure causes command to fail' ' done EOF - # Even though we fail to create refs/tags/tag1 the below command - # unexpectedly succeeds. - git -C clone5 fetch .. $B:refs/heads/something && + test_must_fail git -C clone5 fetch .. $B:refs/heads/something && test $B = $(git -C clone5 rev-parse --verify refs/heads/something) && test $S = $(git -C clone5 rev-parse --verify tag2) && test_must_fail git -C clone5 rev-parse --verify tag1