From patchwork Thu Apr 25 10:18:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Hieber X-Patchwork-Id: 13643054 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 6B97D6EB51 for ; Thu, 25 Apr 2024 10:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040337; cv=none; b=R4DlsR+grmUH93iwbGNsVtUqPRcnG5nYzyRgkHUZ8SCKK1MdDAe16TIe6gms2Uh6z6Sa7EHp5Ij7emmj8QbuAal6iQNj4rwlt/ay2etGRzw1PJpsdd/Vezb6jkscCmpJkueqa2QD6OFrZVTrXH3W/L2V55TfwVIZfBk7Ilu8KNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040337; c=relaxed/simple; bh=BLpYec6Wl0HmYH16pCrfAsbDgcM5B9ZGYS75UGUnfMQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=A/F7aWFH8DGS6PBVis3RpxlZ2MAo9oqYxiZgTdVntBPf49dTsRhlYo8PhcSbong4FKA2N5vDf/K0mHj1OnnD8wtxyg0YfaUtK40Sj4stxBBdpC8ZL8JNCpj6ftXPaE2XS/v3fy6ZV2bzXn3cEwPhTjWx17AnFjbLy/DsqwRX5rw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rzwBn-0005rU-Cm; Thu, 25 Apr 2024 12:18:51 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rzwBm-00EFFE-1R; Thu, 25 Apr 2024 12:18:50 +0200 Received: from rhi by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rzwBl-002yLL-3C; Thu, 25 Apr 2024 12:18:49 +0200 From: Roland Hieber To: git@vger.kernel.org Cc: Roland Hieber , Junio C Hamano , Denton Liu Subject: [PATCH v3 1/3] completion: add 'symbolic-ref' Date: Thu, 25 Apr 2024 12:18:42 +0200 Message-Id: <20240425101845.708554-1-rhi@pengutronix.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: rhi@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: git@vger.kernel.org Even 'symbolic-ref' is only completed when GIT_COMPLETION_SHOW_ALL_COMMANDS=1 is set, it currently defaults to completing file names, which is not very helpful. Add a simple completion function which completes options and refs. Signed-off-by: Roland Hieber --- PATCH v3: - make use of __gitcomp_builtin instead of hard-coded options, and add a test for it (thanks to Patrick Steinhardt) - add empty line between test cases (thanks to Patrick Steinhardt) PATCH v2: https://lore.kernel.org/git/20240424215019.268208-1-rhi@pengutronix.de - no changes PATCH v1: https://lore.kernel.org/git/20240424210549.256256-1-rhi@pengutronix.de/ --- contrib/completion/git-completion.bash | 11 +++++++++++ t/t9902-completion.sh | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 75193ded4bde..4d63fb6eeaf7 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3581,6 +3581,17 @@ _git_svn () fi } +_git_symbolic_ref () { + case "$cur" in + --*) + __gitcomp_builtin symbolic-ref + return + ;; + esac + + __git_complete_refs +} + _git_tag () { local i c="$__git_cmd_idx" f=0 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 569cf2310434..963f865f27ed 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2518,6 +2518,29 @@ test_expect_success 'complete tree filename with metacharacters' ' EOF ' +test_expect_success 'symbolic-ref completes builtin options' ' + test_completion "git symbolic-ref --d" <<-\EOF + --delete Z + EOF +' + +test_expect_success 'symbolic-ref completes short ref names' ' + test_completion "git symbolic-ref foo m" <<-\EOF + main Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'symbolic-ref completes full ref names' ' + test_completion "git symbolic-ref foo refs/" <<-\EOF + refs/heads/main Z + refs/heads/mybranch Z + refs/tags/mytag Z + refs/tags/A Z + EOF +' + test_expect_success PERL 'send-email' ' test_completion "git send-email --cov" <<-\EOF && --cover-from-description=Z From patchwork Thu Apr 25 10:18:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Hieber X-Patchwork-Id: 13643052 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 6B9DA83A1D for ; Thu, 25 Apr 2024 10:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040336; cv=none; b=R3UPIXAijiYt9BWS/xOtOpZKk2Fki6Ie087vHZi+Hewku7srEwXwt+e/GaUz2CH+l2Jon/Fo6cQAPVj4QWhD2JvbSGU7pe37I7x7A7OuTelRQY3fUOWZ6h/HjusAAaG6GWhGkx9ix1PRZvCpj8aP7tgTfTuAEP+H8UbeLHK1SP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040336; c=relaxed/simple; bh=gVsw5IPMVDykcUpjgurCUDOtPHZqMJ0FKOXQhQUyu3c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YcKSnncgd/F2nfzwZz/ZEt5FRRAydFNGabr1JThj4p/48Ai029mfqwIaOp1O+JNRqFRnXokRPvVXF3iaeKjo2AUgGZrtHW1qfydK1jVMixDN51a6rPRVACD8jjDMAEeHdKwHJFU4Zn8AMQgSiX+nSjLN5qIswTH4r2lYRp3PGcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rzwBn-0005rV-Ch; Thu, 25 Apr 2024 12:18:51 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rzwBm-00EFFH-7k; Thu, 25 Apr 2024 12:18:50 +0200 Received: from rhi by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rzwBm-002yLV-0c; Thu, 25 Apr 2024 12:18:50 +0200 From: Roland Hieber To: git@vger.kernel.org Cc: Roland Hieber , Felipe Contreras , Junio C Hamano Subject: [PATCH v3 2/3] completion: improve docs for using __git_complete Date: Thu, 25 Apr 2024 12:18:43 +0200 Message-Id: <20240425101845.708554-2-rhi@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240425101845.708554-1-rhi@pengutronix.de> References: <20240425101845.708554-1-rhi@pengutronix.de> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: rhi@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: git@vger.kernel.org It took me more than a few tries and a good lecture of __git_main to understand that the two paragraphs really only refer to adding completion functions for executables that are not called through git's subcommand magic. Improve the docs and be more specific. Signed-off-by: Roland Hieber --- PATCH v3: new in v3, based on feedback from Junio C Hamano --- contrib/completion/git-completion.bash | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 4d63fb6eeaf7..566f32d412ce 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -31,15 +31,22 @@ # Note that "git" is optional --- '!f() { : commit; ...}; f' would complete # just like the 'git commit' command. # -# If you have a command that is not part of git, but you would still -# like completion, you can use __git_complete: +# If you have a shell command that is not part of git (and is not called as a +# git subcommand), but you would still like git-style completion for it, use +# __git_complete. For example, to use the same completion as for 'git log' also +# for the 'gl' command: # # __git_complete gl git_log # -# Or if it's a main command (i.e. git or gitk): +# Or if the 'gk' command should be completed the same as 'gitk': # # __git_complete gk gitk # +# The second parameter of __git_complete gives the completion function; it is +# resolved as a function named "$2", or "__$2_main", or "_$2" in that order. +# In the examples above, the actual functions used for completion will be +# _git_log and __gitk_main. +# # Compatible with bash 3.2.57. # # You can set the following environment variables to influence the behavior of From patchwork Thu Apr 25 10:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Hieber X-Patchwork-Id: 13643053 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 6BA198614D for ; Thu, 25 Apr 2024 10:18:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040336; cv=none; b=QH73zrbuVbNtjkF2c5plLc3W8pVmLifaNDYn6m60gXeVYPAfiOaXpsqWaPR/j8gu1gxA1w0Ptr4bQ/zIzJYCp1eS0NBKI0vg1PtwiWLEWs47n2ONsb6WJdx4cDNWRY05TDdnFanI8N+ltV4HVrgkjJKZTithRjmL7mstdFB4648= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040336; c=relaxed/simple; bh=PJW2fhdLtPgovMXAYEH9F+/W+8nhU3at4W5RS9yLqFE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ksLed6CCt72PhyZmOqKbBEaSmNzFQT1FRcty0FBd/c3ZoCnicaQtZzZ+msra5SIp4tXtABrbVwY7O7qGhrhPKNZyaHlwRjt8JoLdXb8FF6p6/jicx6tdEyDsi2wuIl2lT8p8hJV7wzRKfSxVrBbm0W4elW8qAGyjf1jvqSKrQEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rzwBn-0005rW-Ce; Thu, 25 Apr 2024 12:18:51 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rzwBm-00EFFK-DV; Thu, 25 Apr 2024 12:18:50 +0200 Received: from rhi by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rzwBm-002yLf-1C; Thu, 25 Apr 2024 12:18:50 +0200 From: Roland Hieber To: git@vger.kernel.org Cc: Roland Hieber , Junio C Hamano Subject: [PATCH v3 3/3] completion: add docs on how to add subcommand completions Date: Thu, 25 Apr 2024 12:18:44 +0200 Message-Id: <20240425101845.708554-3-rhi@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240425101845.708554-1-rhi@pengutronix.de> References: <20240425101845.708554-1-rhi@pengutronix.de> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: rhi@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: git@vger.kernel.org Signed-off-by: Roland Hieber --- PATCH v3: - change the wording a bit to make the text more fluent PATCH v2: https://lore.kernel.org/git/20240424215019.268208-2-rhi@pengutronix.de - fix typo and superfluous "-my" (thanks to Junio C Hamano) PATCH v1: https://lore.kernel.org/git/20240424210549.256256-2-rhi@pengutronix.de/ --- contrib/completion/git-completion.bash | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 566f32d412ce..5c0ddeb3d4fb 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -31,6 +31,13 @@ # Note that "git" is optional --- '!f() { : commit; ...}; f' would complete # just like the 'git commit' command. # +# To add completion for git subcommands that are implemented in external +# scripts, define a function of the form '_git_${subcommand}' while replacing +# all dashes with underscores, and the main git completion will make use of it. +# For example, to add completion for 'git do-stuff' (which could e.g. live +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'. +# See _git_show, _git_bisect etc. below for more examples. +# # If you have a shell command that is not part of git (and is not called as a # git subcommand), but you would still like git-style completion for it, use # __git_complete. For example, to use the same completion as for 'git log' also