From patchwork Mon Jan 15 10:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519489 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 47E5A1E86B for ; Mon, 15 Jan 2024 10:36:02 +0000 (UTC) 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="LHvhu4MI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sjM0GoZo" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 66A8D5C0129; Mon, 15 Jan 2024 05:36:01 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 15 Jan 2024 05:36:01 -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=fm3; t=1705314961; x=1705401361; bh=/D4chCHc7I ayETMg/xYJnlNXiRWeNoreSBjnfRG29Cs=; b=LHvhu4MIQYIBFNBIYfUOIgVyqN 6yWzeMgLTKdpPuxmcthaku1kUp9L0mcX8yE/V3jRC5chr3+zhE/Xn8HtEGnYzwrS Misa+b86Iz9rlm7iNgcsWS9PSQiffHQgPJoSRxVEDXLdNeVtispnQXec6cLKbpQN 6TYrBoQ8jZNVyHbWLd5IK6Z/2TWLuWuZ66g0ely/H1grhJvzn9xI85JnqoXh9tpw HH68Qu49LfPBvZbHBKMDCybUezJNGiJVwb8//4u5/t3T9R1hr+p4OOeIXUQttNy5 lR4jYbdDbVON7SNddmtasRFrXy7AxiuSvQVMXRxnluqVDVOUfO3XkcPaYz8g== 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=1705314961; x=1705401361; bh=/D4chCHc7IayETMg/xYJnlNXiRWe NoreSBjnfRG29Cs=; b=sjM0GoZo35B+VHIJFpaaYEMEGxrQfVZjh9xt+au5MOJq ypVnvWyux4lP6Ta1hLPLm/qjXyLQp+lrmhMfLwxXeW3T+k+b3bdZmkIgI7khirX9 GivtaxkQtDiKV8P+r/l0DwHXBxh8zMOwi22eaK8uWX8AhPaKk6vRWGwn2sN0ELsN Y2T6THp6d0G1n6KsVD/gAXsD4QmISETzgDxgktUapOxPUJUjxSehjr61xp9Ac1n2 nKNfSQniubB2fQpeLC9d0qqGrMEDYX57vjSZ4sw7X/AxHiqEYnI7YROpXJ7BdF4I v1i5OLV99bYHRe1LBPrDyxRpos5ewWjJ7Z012E72LA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:00 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 85304bf0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:09 +0000 (UTC) Date: Mon, 15 Jan 2024 11:35:57 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 1/5] completion: discover repo path in `__git_pseudoref_exists ()` Message-ID: <8b6a45664a210ca5a18810fc6a8ff95823f92390.1705314554.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: The helper function `__git_pseudoref_exists ()` expects that the repo path has already been discovered by its callers, which makes for a rather fragile calling convention. Refactor the function to discover the repo path itself to make it more self-contained, which also removes the need to discover the path in some of its callers. Signed-off-by: Patrick Steinhardt --- contrib/completion/git-completion.bash | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 8c40ade494..06a9107449 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -138,6 +138,8 @@ __git_pseudoref_exists () { local ref=$1 + __git_find_repo_path + # If the reftable is in use, we have to shell out to 'git rev-parse' # to determine whether the ref exists instead of looking directly in # the filesystem to determine whether the ref exists. Otherwise, use @@ -1656,7 +1658,6 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options _git_cherry_pick () { - __git_find_repo_path if __git_pseudoref_exists CHERRY_PICK_HEAD; then __gitcomp "$__git_cherry_pick_inprogress_options" return @@ -2966,7 +2967,6 @@ _git_reset () _git_restore () { - __git_find_repo_path case "$prev" in -s) __git_complete_refs @@ -2995,7 +2995,6 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options _git_revert () { - __git_find_repo_path if __git_pseudoref_exists REVERT_HEAD; then __gitcomp "$__git_revert_inprogress_options" return From patchwork Mon Jan 15 10:36:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519490 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 A66312BB00 for ; Mon, 15 Jan 2024 10:36:06 +0000 (UTC) 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="IiVL3DKG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NKSpicBC" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id EAE165C014E; Mon, 15 Jan 2024 05:36:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 15 Jan 2024 05:36:05 -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=fm3; t=1705314965; x=1705401365; bh=NMggkPHpcr wZ5mqgaV0NugbexY7ZTVt6sQ/Hw/6hP8w=; b=IiVL3DKG6k6o+aATvuYQP6tC1N fjPr1EktwNbUUgaXn2OUgCAFbgomS1tKY2xdx+llO1Yt4oErFR8nwpSzAi22cCjw n4lbYpgDb45pc5N3GRHkIFfJ/OZajt6BdY2yMfX20vjMygBhkZ6rI54mGqN8Vqkl Ghpv/TgEiySgXSXIIhEcWBLIYOFQz6ltNoxCQWaUO6kUeWM3u1DZR6VU/Hd4rlmv mqAfXDQNXXLD61+Ul1EjJXWy/Qh6lY35XTm8tymGhPed/sVYo3KIY8BMr72/5gZ1 dgXWHclpwG1SbDaCXrCGMWWOOaXTjrkKitE1ePDTOJQEDettzvu8GJXlQNRA== 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=1705314965; x=1705401365; bh=NMggkPHpcrwZ5mqgaV0NugbexY7Z TVt6sQ/Hw/6hP8w=; b=NKSpicBCfvIaHik/2AByqD/pheDWmEj3eOus8OIFoXYi EJMldqtrK+xHyu/2MGQAFjQ/SSy+xGBaB0dVb/XsTkISmCL6/dQu5vCX3XXRAZkP +W5Qg9nZ6GVcTuTAihga7Ep2Yjh7UM45uTK+EANDNzHvuU/oWNgelvd59MgIGjNp /hUE/PE+85s2UqkuHh6QmhxqLko2/8KKrgZtsedmmZmnD7h3o8YiLpbQGs89aePy GazH/jk04zcEbTHdg967XOht7b1wCMENApOKOi1JY/yJZBco/qncg40b8jp3lV2P 9HJwYMEwp6CG5a1MvGpY60ZAvZ+0rwcOghpOJGzSlg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:04 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 16b558e1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:14 +0000 (UTC) Date: Mon, 15 Jan 2024 11:36:02 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 2/5] t9902: verify that completion does not print anything Message-ID: <84b3546a8d8961ce77a2d55e67b91c9d61bbf351.1705314554.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: The Bash completion script must not print anything to either stdout or stderr. Instead, it is only expected to populate certain variables. Tighten our `test_completion ()` test helper to verify this requirement. Signed-off-by: Patrick Steinhardt --- t/t9902-completion.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index aa9a614de3..95ec762a74 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -5,6 +5,12 @@ test_description='test bash completion' +# The Bash completion scripts must not print anything to either stdout or +# stderr, which we try to verify. When tracing is enabled without support for +# BASH_XTRACEFD this assertion will fail, so we have to mark the test as +# untraceable with such ancient Bash versions. +test_untraceable=UnfortunatelyYes + . ./lib-bash.sh complete () @@ -87,9 +93,11 @@ test_completion () else sed -e 's/Z$//' |sort >expected fi && - run_completion "$1" && + run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 && sort out >out_sorted && - test_cmp expected out_sorted + test_cmp expected out_sorted && + test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output && + rm "$TRASH_DIRECTORY"/bash-completion-output } # Test __gitcomp. From patchwork Mon Jan 15 10:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519491 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 035CF2C68B for ; Mon, 15 Jan 2024 10:36:09 +0000 (UTC) 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="c3Oaup4e"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="STtVsiyh" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4EEBA5C011D; Mon, 15 Jan 2024 05:36:09 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 15 Jan 2024 05:36:09 -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=fm3; t=1705314969; x=1705401369; bh=+Y0V8uYcmE 3A65OAsGja2Dp1vjjNDZ+r/WDP0ilS4Rs=; b=c3Oaup4evqJOarpCOOuqS3l51r EpQIfIpj3BCpZVaYlUfRoaDjNUS7PNwpR4LA+PWsDIZwvqS/EpD6xVhijfV0NeLg C7kYBrqLayHA2vmde4XQQkiem5HsUtTE4VdluFyw6FB2hukShwMkpFdd1Tg0db5A OtyoxT36jeeWday2MCmuYPOZAg5UHhTKfr4ZZyziRLfD/FLk6Yc2IMjefFCI2iuu dlG+hig/LMaRlh8Sjt9CJh3mNcItBqvO4DB8dJLKkhPEw6olmE8WhAdfXeAr9r94 9E+/zqWoi3Af437PKI/OWCZuXYNnAc11Hnwtz6do/YGKdpJAe3ikVBy5nlqQ== 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=1705314969; x=1705401369; bh=+Y0V8uYcmE3A65OAsGja2Dp1vjjN DZ+r/WDP0ilS4Rs=; b=STtVsiyhX5ooU6BFfAgiOGDecuSNSj9DcO89m8YmEwV8 y+iNitsQoqRl/QKwsf3I7W/llCAo9b1CuZyl+eqV1O1GcvQMOkk3o7/NOyLmzFJU 4WDpab21Q/itreO5svyuVsVoDVnsgZoK+i+4V8rG0Ybtzz3wCTyFW/Fpd6x2QNkz gqVvhJgbAnyddjWscF6+blNcafkeGjAptsAc10stcAapFJLwXpVvc+t6aHdph8zF 3llipurFhqVQV31fvCYU64JCaaJomUkblWX04EIqr7Owlzaa13QpibII2WzjXvk5 sBGW5DbQRytG2bs5fwcect1cuBYxVHUJOOafhbLEzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtudenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepfedvleefueetgeeitdekheelffekkefgffduhfduvdefffdtheekiefhkeejkeeh necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:08 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9e03a28b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:18 +0000 (UTC) Date: Mon, 15 Jan 2024 11:36:06 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 3/5] completion: improve existence check for pseudo-refs 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: Improve the existence check along the following lines: - Stop stripping the "ref :" prefix and compare to the expected value directly. This allows us to drop a now-unused variable that was previously leaking into the user's shell. - Mark the "head" variable as local so that we don't leak its value into the user's shell. - Stop manually handling the `-C $__git_repo_path` option, which the `__git ()` wrapper aleady does for us. - In simlar spirit, stop redirecting stderr, which is also handled by the wrapper already. Suggested-by: SZEDER Gábor Signed-off-by: Patrick Steinhardt --- contrib/completion/git-completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 06a9107449..d703e3e64f 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -137,6 +137,7 @@ __git_eread () __git_pseudoref_exists () { local ref=$1 + local head __git_find_repo_path @@ -146,9 +147,8 @@ __git_pseudoref_exists () # Bash builtins since executing Git commands are expensive on some # platforms. if __git_eread "$__git_repo_path/HEAD" head; then - b="${head#ref: }" - if [ "$b" == "refs/heads/.invalid" ]; then - __git -C "$__git_repo_path" rev-parse --verify --quiet "$ref" 2>/dev/null + if [ "$head" == "ref: refs/heads/.invalid" ]; then + __git rev-parse --verify --quiet "$ref" return $? fi fi From patchwork Mon Jan 15 10:36:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519492 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 8C8EB2C698 for ; Mon, 15 Jan 2024 10:36:15 +0000 (UTC) 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="Jm/p8VLF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="xBT96D3T" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A70B55C0116; Mon, 15 Jan 2024 05:36:14 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 15 Jan 2024 05:36:14 -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=fm3; t=1705314974; x=1705401374; bh=GLgfuGvyXf cNMjT/sr7AAB5ySabc4XXRsE4uYSqDCgo=; b=Jm/p8VLFlZxm0QouRyDryfPrwx fHfAuBJV1OSpcQsdl2GfkTyoZnNPyAyJ5g1CE5N3GNXGVMQv/cvyTyCAWyuWlY6u fEr5T+KnQiue8+YrsRaOrxldEorRPrvkMi8i+XmMCD8OOvjnkANbV66ovXkwRJL7 yOzvQtJjEOil7xpnMu5g2E7FkXWvjYEfBmJeUZdeANXcBEGiRY4qjOrC5BIGK0ct 0id65xEegKmy2qehUeNYUXzInCAl0Z9TFWtPPSQ4CdFq1sQsDvKN0PzKO7KyVgY8 zAaz7K/1+9w9IyRv4128otMZJLTiYYSamzlvo3V5uCtA0eT6jC8T+mLm2cJw== 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=1705314974; x=1705401374; bh=GLgfuGvyXfcNMjT/sr7AAB5ySabc 4XXRsE4uYSqDCgo=; b=xBT96D3TlLEn3/ra+W7a0p5JMKfvncnk4wpOt4PfIG+A KJ9O9eWvd8vGhI4x9TanXdbcq5ThQbLhN1W/F5p72pPCxkIv7sgdwku7z3RDtVWF S9PGWURWMAlxm06uYb7xx4XRTUQ0rv3E31MLH7IlLQlqf4KW7e7wQNi+nzXO1X41 1j+MxcUI+qRVrwsb0yols3w3pZKY2mB5Ke582+4KhUilQ5ZWRPCN+7RpS3b86cIG /zgs7ArSpZGw62x+cCBhBw9PaMHB7ts73xYhQcA5LNJxEB5Oc/rMQBfDIIJ13C8m BwH6yO354SsJySlrYUhAjhNzOrcXLOoBGHlyGw0tug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:13 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1fd6cda6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:23 +0000 (UTC) Date: Mon, 15 Jan 2024 11:36:11 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 4/5] completion: silence pseudoref existence check Message-ID: <4de00121b24f31d21e54738a4645eefa3d283374.1705314554.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: In 44dbb3bf29 (completion: support pseudoref existence checks for reftables, 2023-12-19), we have extended the Bash completion script to support future ref backends better by using git-rev-parse(1) to check for pseudo-ref existence. This conversion has introduced a bug, because even though we pass `--quiet` to git-rev-parse(1) it would still output the resolved object ID of the ref in question if it exists. Fix this by redirecting its stdout to `/dev/null` and add a test that catches this behaviour. Note that the test passes even without the fix for the "files" backend because we parse pseudo refs via the filesystem directly in that case. But the test will fail with the "reftable" backend. Helped-by: Jeff King Helped-by: Johannes Schindelin Signed-off-by: Patrick Steinhardt --- contrib/completion/git-completion.bash | 2 +- t/t9902-completion.sh | 31 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index d703e3e64f..54ce58f73d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -148,7 +148,7 @@ __git_pseudoref_exists () # platforms. if __git_eread "$__git_repo_path/HEAD" head; then if [ "$head" == "ref: refs/heads/.invalid" ]; then - __git rev-parse --verify --quiet "$ref" + __git rev-parse --verify --quiet "$ref" >/dev/null return $? fi fi diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 95ec762a74..56dc7343a2 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1933,6 +1933,14 @@ test_expect_success 'git checkout - --orphan with branch already provided comple EOF ' +test_expect_success 'git restore completes modified files' ' + test_commit A a.file && + echo B >a.file && + test_completion "git restore a." <<-\EOF + a.file + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag && @@ -2728,4 +2736,27 @@ test_expect_success '__git_complete' ' test_must_fail __git_complete ga missing ' +test_expect_success '__git_pseudoref_exists' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + sane_unset __git_repo_path && + + # HEAD points to an existing branch, so it should exist. + test_commit A && + __git_pseudoref_exists HEAD >output 2>&1 && + test_must_be_empty output && + + # CHERRY_PICK_HEAD does not exist, so the existence check should fail. + ! __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 && + test_must_be_empty output && + + # CHERRY_PICK_HEAD points to a commit, so it should exist. + git update-ref CHERRY_PICK_HEAD A && + __git_pseudoref_exists CHERRY_PICK_HEAD >output 2>&1 && + test_must_be_empty output + ) +' + test_done From patchwork Mon Jan 15 10:36:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13519493 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 CC13F1E865 for ; Mon, 15 Jan 2024 10:36:19 +0000 (UTC) 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="IxJK/ET8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Nr7RJVMQ" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 0282C5C00ED; Mon, 15 Jan 2024 05:36:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 15 Jan 2024 05:36: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:subject :subject:to:to; s=fm3; t=1705314978; x=1705401378; bh=wCCU/d1kLL TS0GW0fA+45QZMekQzArGY+W8T/+Wk0V0=; b=IxJK/ET8ByMUe6D35Gm4NMq6QW s/xQU/noSTykl6c7WvJtIF7MOPsVK2MB7tA9SobBvkTqpjizhHc1pp33VYvKjLt9 HE4/jNaePNihSm62s27uT89A8gHh5QXlE9qChpPHq7CoVrb9wNr5V2rimID9aNqy DJ+vBzE/eee+yrgXeWrZnmPBxXxd3X+cDm8xH240n5155FYeuPMK4/cogZTH9RgD xmEMOb9C9WHk0n/iNr3plmrK5DUHE6eMkL9dAOtLQooJYFep4g8p2d8Z6SvLUL8C FWvicpcPD5qUW1xtPHU0kxod4ol1FX/QTq7aIELYV/FVLy1nwIJHtfDqJp/A== 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=1705314978; x=1705401378; bh=wCCU/d1kLLTS0GW0fA+45QZMekQz ArGY+W8T/+Wk0V0=; b=Nr7RJVMQQBFTJUEVAmBzVlohmi4ofaP++Gp39DSQLloq ArEOd/DZAtndVAYpoKCEZxojb2/OrwJaGWg8vxXpA4xLi5keqOOIY52oBh8Qmvrp LlbZZ37ILobnzCe/CuBkhNvcj/BOy1TGKa23zulBhWRRKRGv4PAA4L/UXM1ZeUFA BlQE6XH/Ul9VFYHhqYF/erUcCt8RYCkbX6ibrpfheDv0n5E3P3V1r2CNZdq2+Wqi UWd8ReI+Po3bckfBBw9L42JE25wylYLILqzp6K/gENz/GiAcW/1w8wDxAKmDDK/C veNeyapGBCeXcCbTIBeA0ir0DqiExDHMNohFU+/EDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jan 2024 05:36:17 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 78e833b9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 15 Jan 2024 10:33:27 +0000 (UTC) Date: Mon, 15 Jan 2024 11:36:15 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Stan Hu , SZEDER =?iso-8859-1?q?G=E1bor?= , Jeff King , Johannes Schindelin , Junio C Hamano Subject: [PATCH v2 5/5] completion: treat dangling symrefs as existing pseudorefs Message-ID: <22269af050fc9379c1049afb8ae51cbfec2a3670.1705314554.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: The `__git_pseudoref_exists ()` helper function back to git-rev-parse(1) in case the reftable backend is in use. This is not in the same spirit as the simple existence check that the "files" backend does though, because there we only check for the pseudo-ref to exist with `test -f`. With git-rev-parse(1) we not only check for existence, but also verify that the pseudo-ref resolves to an object, which may not be the case when the pseudo-ref points to an unborn branch. Fix this issue by using `git show-ref --exists` instead. Note that we do not have to silence stdout anymore as git-show-ref(1) will not print anything. Signed-off-by: Patrick Steinhardt --- contrib/completion/git-completion.bash | 2 +- t/t9902-completion.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 54ce58f73d..6662db221d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -148,7 +148,7 @@ __git_pseudoref_exists () # platforms. if __git_eread "$__git_repo_path/HEAD" head; then if [ "$head" == "ref: refs/heads/.invalid" ]; then - __git rev-parse --verify --quiet "$ref" >/dev/null + __git show-ref --exists "$ref" return $? fi fi diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 56dc7343a2..35eb534fdd 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2743,6 +2743,10 @@ test_expect_success '__git_pseudoref_exists' ' cd repo && sane_unset __git_repo_path && + # HEAD should exist, even if it points to an unborn branch. + __git_pseudoref_exists HEAD >output 2>&1 && + test_must_be_empty output && + # HEAD points to an existing branch, so it should exist. test_commit A && __git_pseudoref_exists HEAD >output 2>&1 &&