From patchwork Tue May 7 04:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13656226 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0613B6A8CF for ; Tue, 7 May 2024 04:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057594; cv=none; b=hf5HgO/WAAmeClgra3RnKRKT54ewiK9i47yUo0aqguzkEwubmiQ/QIkYlm2yAaFCVL/I0CpMbpOicvLiwMMW0xNSjiGVDIemiDFASTM9gbwkMeWphwkoHHB043pd2Qp61F5Up5iT/exvVvBzaeUsyXMQYR34Gwc6PRyDnX6Wqoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715057594; c=relaxed/simple; bh=eVSKxBKG5Zcaks94GkwuH9/ZK1uXYptOvHxFszcIwnw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l7xL+y4SpsOzenr6nn8CcRNxC6tpHTPG+0Xq573QEQ8aXq5Y79YlT9ciQMamSAD3gt7bdKZ01r+Ws84YboBgCZjEo9OFO6ZVkDB8asiM5GzHZwgRcWAlXgFvoSfqPOommeOWiAX9dmJs3qaA8FhcRAH0PAs51q8JjgWGNqesze8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=l+KbtFxt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ritcu0Wq; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="l+KbtFxt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ritcu0Wq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A1E5D1140156; Tue, 7 May 2024 00:53:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 07 May 2024 00:53:09 -0400 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=fm3; t=1715057589; x=1715143989; bh=yUjhLdCJR3 wpC8t5zUGcB6E0Qq8OZxSX099He/dQgyU=; b=l+KbtFxtTAC0zhhniXYiXZZ+NO WmB1bLQoRqSaLuCt7gCfcVmQp9neA8Rq+DykiJvmPxDe7KVzePRvDRq0SmVoM8gK 0RVhcX6f+f5jwKysFyO9tAHSta32FfC6rtljYnMygy7kk8EyMdYGH49bdbsmSX2I l63rzqKlPeclxnYRr0X0coW2fm3FvvgAZlELNYYRXtpKyZLlzJ7SCBTFwAHDBH2+ wFFnjx3sB1EZGSKnU88vMPggaHoIU7jIsPZEM0Wum6wxMLShw+u6ekl0P/LBj3ov X5QLx3tdU6ZUauIOJqlD0Xs5317jASHTZLT/eDPMvzHcSQhvyKuzHULTMxeA== 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= fm3; t=1715057589; x=1715143989; bh=yUjhLdCJR3wpC8t5zUGcB6E0Qq8O ZxSX099He/dQgyU=; b=Ritcu0WqUQgPWdcu0aE/j/ZmmkeiHYLEwmzFrec3XCN/ 4951S2+VTxeD0XtdQ7xRRgZisY+kQOzn9hjpq7GonrRRZ+gW3C/KeYT8XZZtCGag s/dDPODjWG8Jm0zu2fHMFbsvQ2aJ93ryS2SPFTgCIGhyIWFBH04DP4Ftor5Y4X3+ G7JrERE95WgT/8aqGN5B5QFlgaH10FDqXJ759l+QHQ6zRyutwY56wwH4CK7AEvgL QL/RQvaV/0qFJuEs4v+7WcHTgERVAWGUe5KcnWx9p2WRJLYJC44bzmMCsRDUVc0/ jY6fQZMZQEBjMunf3oYzkZphKHLLv8dbEghqWlj4Zw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 May 2024 00:53:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id cd89540c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 May 2024 04:53:00 +0000 (UTC) Date: Tue, 7 May 2024 06:53:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Justin Tobler Subject: [PATCH v4 05/13] attr: fix BUG() when parsing attrs outside of repo Message-ID: 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: If either the `--attr-source` option or the `GIT_ATTR_SOURCE` envvar are set, then `compute_default_attr_source()` will try to look up the value as a treeish. It is possible to hit that function while outside of a Git repository though, for example when using `git grep --no-index`. In that case, Git will hit a bug because we try to look up the main ref store outside of a repository. Handle the case gracefully and detect when we try to look up an attr source without a repository. Signed-off-by: Patrick Steinhardt --- attr.c | 6 ++++++ t/t0003-attributes.sh | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/attr.c b/attr.c index a5b717e4ce..c89ab3478e 100644 --- a/attr.c +++ b/attr.c @@ -1226,8 +1226,14 @@ static int compute_default_attr_source(struct object_id *attr_source) if (!default_attr_source_tree_object_name) return 0; + if (!startup_info->have_repository) { + if (!ignore_bad_attr_tree) + die(_("cannot use --attr-source or GIT_ATTR_SOURCE without repo")); + return 0; + } + if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, attr_source)) { if (!ignore_bad_attr_tree) diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index d755cc3c29..72fadca1e8 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -433,8 +433,23 @@ test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tre test_cmp expect actual ) ' +test_expect_success 'diff without repository with attr source' ' + mkdir -p "$TRASH_DIRECTORY/outside/nongit" && + ( + cd "$TRASH_DIRECTORY/outside/nongit" && + GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/outside" && + export GIT_CEILING_DIRECTORIES && + touch file && + cat >expect <<-EOF && + fatal: cannot use --attr-source or GIT_ATTR_SOURCE without repo + EOF + test_must_fail env GIT_ATTR_SOURCE=HEAD git grep --no-index foo file 2>err && + test_cmp expect err + ) +' + test_expect_success 'bare repository: with --source' ' ( cd bare.git && attr_check_source foo/bar/f f tag-1 &&