From patchwork Thu Dec 14 13:37:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13493085 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Zm+NYHBC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Eiz4Fblj" Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE638111 for ; Thu, 14 Dec 2023 05:37:06 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 22F205C0163; Thu, 14 Dec 2023 08:37:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 14 Dec 2023 08:37:06 -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:subject :subject:to:to; s=fm1; t=1702561026; x=1702647426; bh=IlRA5wR2O/ /F2fNfr00UfjVZHFHDvVtJMlc/L+cUd8M=; b=Zm+NYHBCGuSsNqXArvn9y+4pjD 4ovrYIqY6SRieJAnApWjnLFotg2dTv0PGKylxhIWko7DKW1BRj7UjupfvOIho9x7 LgKPLgogS4MkyBRCzBv/FKk4XEx/13oQDR35qlBpL5+P5N8Ee5Y9iyHGtfVqCvej kK4A+sJwl5htAEpmOc/gB0CQCKOwbGLUYSXRxzt+70L/yUOI2dGtKd3LLPig+VWc V9Fgbw9yC7uGSgAlv0fTtsymDJGQ+9rZccsfBke7zI1QudAB4AafzC4Ph5cg1K4/ LNWlKqwZkdxEe8wPgPtOv1WMYW/SCR8ozSUfkDmX89mpY/6GheN0FzTgRKQQ== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1702561026; x=1702647426; bh=IlRA5wR2O//F2fNfr00UfjVZHFHD vVtJMlc/L+cUd8M=; b=Eiz4Fblj1TTv2AKZcIz8q9N5lwBxYBQbZxvQRLSiWkQ8 lsC6+HCfQqiiUr9dQoEt6AwiyYspgEDSXRg0bPhIwCDsldF+sfZpPY/hBbllJXS6 7Gay8eXte+5A4pe54m92oL7l+njkvhQ1qIkmDq1Ww66o96K4uu4v8A4se5obt+eM A4PlIdn+Awaw77NB1qciu6dU1B/tqR052KOQ+u6odh9oug5K1uZxNi/EaB/4n6PZ 69AuIwPrEQUIqrCpgyQwckKkwAUi08m8SXS4k0yTMDUiEodtiOPIac8T4frO4PAn nCpHNvEut2rjitywl1XuomTAnY8TOUDiLix1++OHVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelledgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 08:37:04 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f2fc1b14 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 14 Dec 2023 13:35:21 +0000 (UTC) Date: Thu, 14 Dec 2023 14:37:02 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Taylor Blau , Phillip Wood , Ramsay Jones Subject: [PATCH v3 2/4] refs: propagate errno when reading special refs fails Message-ID: <455ab69177586370b809b4a790ae99ce5e97dafa.1702560829.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 | 4 +++- t/t1403-show-ref.sh | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index fcae5dddc6..00e72a2abf 100644 --- a/refs.c +++ b/refs.c @@ -1806,8 +1806,10 @@ 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) + 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..66e6e77fa9 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -266,4 +266,14 @@ 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' ' + test_when_finished "rm .git/FETCH_HEAD" && + git rev-parse HEAD >.git/FETCH_HEAD && + git show-ref --exists FETCH_HEAD +' + test_done