From patchwork Wed Nov 29 08:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13472395 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Ies01mgT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FWDY72cm" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93DA310F0 for ; Wed, 29 Nov 2023 00:14:19 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 0931D5C019A; Wed, 29 Nov 2023 03:14:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Wed, 29 Nov 2023 03:14:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type: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=fm1; t=1701245659; x=1701332059; bh=4a ozz/LRTywzThS/k6RiZoDjKh/OUqKhbP+LK3WJKto=; b=Ies01mgTzY1XzGMtOQ +Bj0buSlNiw0n3HJgZ4HgGTkmvMqi1szfli1/kEeY6FVc+m6sa1IJQOpuq7/4Bu4 X5LAy9MYPWt//jrsVKEfOD4b1wvIwgwe9VdyLF9u39ObbQhaIQTIVRRNVTJRSDuT RGpouqR4+U+38lP+nkreKbp0hliKEGzJcOox67mIVOviTPhf8ujus4O2iWzW5TxB pO9IHw1bqEo+ROtQujpWom+R0Cxzw5XMdVKTw0GqLorvnIjBAtVjidCIxlkKZc7B 75QvhBTs0k9Fx1U9MzVHXJI2u8Dze3u0EzTPiRz22Wtm5siXuokm9eJ8x+TySoRl qdZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id: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=fm1; t=1701245659; x=1701332059; bh=4aozz/LRTywzT hS/k6RiZoDjKh/OUqKhbP+LK3WJKto=; b=FWDY72cmKY8ZhAZe2EDc9YynNpBdZ U7jfCkanlTZjZRhv6IiCqjK6qLbt1hBi/HskuOvKLLbjYD3ODtTpnG988E+gOLEc t9Mc3aHVt+n7DOfIpJ7PyZyx7H2cgEUME5WHw2pmaYtbmOpd+K9aj3UWY8VsJGlJ +J4goPB9Lgk7u2SOJS0vLdXvMHEzyNBqYbbYJ5bOPyjXHrfhaa9V/Wz6RfbLvEsu F0wOLHfjn/0TMPtUOYGauTENcrvXKrE/oOkbcsaS5XC8gYcG7uNMIO/GNveTAqml yqQyhxDAVLeq/NBLGhrUbUPs87wP3TT+ezxBuGWLiF+al69AlFxrEDsXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeigedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkfhggtggujgesgh dtreertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhs sehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepueektdevtdffveeljeetgfehheeige ekleduvdeffeeghefgledttdehjeelffetnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Nov 2023 03:14:18 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 81325a37 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 29 Nov 2023 08:13:07 +0000 (UTC) Date: Wed, 29 Nov 2023 09:14:16 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: hanwenn@gmail.com Subject: [PATCH 2/4] refs: propagate errno when reading special refs fails Message-ID: <691552a17ec587b0c03e758437c33d58767803aa.1701243201.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Some refs in Git are more special than others due to reasons explained in the next commit. These refs are read via `refs_read_special_head()`, but this function doesn't behave the same as when we try to read a normal ref. Most importantly, we do not propagate `failure_errno` in the case where the reference does not exist, which is behaviour that we rely on in many parts of Git. Fix this bug by propagating errno when `strbuf_read_file()` fails. Signed-off-by: Patrick Steinhardt --- refs.c | 6 +++++- t/t1403-show-ref.sh | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index fcae5dddc6..7d4a057f36 100644 --- a/refs.c +++ b/refs.c @@ -1806,8 +1806,12 @@ static int refs_read_special_head(struct ref_store *ref_store, int result = -1; strbuf_addf(&full_path, "%s/%s", ref_store->gitdir, refname); - if (strbuf_read_file(&content, full_path.buf, 0) < 0) + errno = 0; + + if (strbuf_read_file(&content, full_path.buf, 0) < 0) { + *failure_errno = errno; goto done; + } result = parse_loose_ref_contents(content.buf, oid, referent, type, failure_errno); diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh index b50ae6fcf1..37af154d27 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -266,4 +266,13 @@ test_expect_success '--exists with directory fails with generic error' ' test_cmp expect err ' +test_expect_success '--exists with non-existent special ref' ' + test_expect_code 2 git show-ref --exists FETCH_HEAD +' + +test_expect_success '--exists with existing special ref' ' + git rev-parse HEAD >.git/FETCH_HEAD && + git show-ref --exists FETCH_HEAD +' + test_done