From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Hongyi Zhao" <hongyi.zhao@gmail.com>,
"Johannes Sixt" <j6t@kdbg.org>,
"Philippe Blain" <levraiphilippeblain@gmail.com>,
"João Victor Bonfim"
<JoaoVictorBonfim+Git-Mail-List@protonmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS
Date: Tue, 25 Jan 2022 13:49:04 +0100 [thread overview]
Message-ID: <patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com> (raw)
In-Reply-To: <CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com>
Add a GIT_COMPLETION_SHOW_ALL_COMMANDS=1 configuration setting to go
with the existing GIT_COMPLETION_SHOW_ALL=1 added in
c099f579b98 (completion: add GIT_COMPLETION_SHOW_ALL env var,
2020-08-19).
This will include plumbing commands such as "cat-file" in "git <TAB>"
and "git c<TAB>" completion. Without/with this I have 134 and 243
completion with git <TAB>, respectively.
It was already possible to do this by tweaking
GIT_COMPLETION_SHOW_ALL_COMMANDS from the outside, that testing
variable was added in 84a97131065 (completion: let git provide the
completable command list, 2018-05-20). Doing this before loading
git-completion.bash worked:
export GIT_TESTING_PORCELAIN_COMMAND_LIST="$(git --list-cmds=builtins,main,list-mainporcelain,others,nohelpers,alias,list-complete,config)"
But such testing variables are not meant to be used from the outside,
and we make no guarantees that those internal won't change. So let's
expose this as a dedicated configuration knob.
1. https://lore.kernel.org/git/CAGP6POJ9gwp+t-eP3TPkivBLLbNb2+qj=61Mehcj=1BgrVOSLA@mail.gmail.com/
Reported-by: Hongyi Zhao <hongyi.zhao@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
n Sat, Jan 22 2022, Hongyi Zhao wrote:
> On Ubuntu 20.04.3 LTS, I use the following git version installed from
> its apt repository:
>
> $ git --version
> git version 2.25.1
>
> I find that there are some sub-commands can't be completed by TAB key
> [...]
Others have explained why this happens, but as noted above an easy but
undocumented workaround for this that I use, because I'd like
e.g. "cat-file" to show up in this completion. In your ~/.bashrc or
equivalent do something like this before it loads git-completion.bash:
export GIT_TESTING_PORCELAIN_COMMAND_LIST="$(git --list-cmds=builtins,main,others,alias)"
But it would be even nicer to turn that into a first-class feature,
this patch does so. With this you can just do:
export GIT_COMPLETION_SHOW_ALL_COMMANDS=1
contrib/completion/git-completion.bash | 13 ++++++++++++-
t/t9902-completion.sh | 27 ++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 377d6c5494a..2436b8eb6b9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -49,6 +49,11 @@
# and git-switch completion (e.g., completing "foo" when "origin/foo"
# exists).
#
+# GIT_COMPLETION_SHOW_ALL_COMMANDS
+#
+# When set to "1" suggest all commands, including plumbing commands
+# which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
+#
# GIT_COMPLETION_SHOW_ALL
#
# When set to "1" suggest all options, including options which are
@@ -3455,7 +3460,13 @@ __git_main ()
then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else
- __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
+ local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
+
+ if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
+ then
+ list_cmds=builtins,$list_cmds
+ fi
+ __gitcomp "$(__git --list-cmds=$list_cmds)"
fi
;;
esac
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 98c62806328..e3ea6a41b00 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2432,6 +2432,33 @@ test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
EOF
'
+test_expect_success 'plumbing commands are excluded without GIT_COMPLETION_SHOW_ALL_COMMANDS' '
+ . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+ sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
+
+ # Just mainporcelain, not plumbing commands
+ run_completion "git c" &&
+ grep checkout out &&
+ ! grep cat-file out
+'
+
+test_expect_success 'all commands are shown with GIT_COMPLETION_SHOW_ALL_COMMANDS (also main non-builtin)' '
+ . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
+ GIT_COMPLETION_SHOW_ALL_COMMANDS=1 &&
+ export GIT_COMPLETION_SHOW_ALL_COMMANDS &&
+ sane_unset GIT_TESTING_PORCELAIN_COMMAND_LIST &&
+
+ # Both mainporcelain and plumbing commands
+ run_completion "git c" &&
+ grep checkout out &&
+ grep cat-file out &&
+
+ # Check "gitk", a "main" command, but not a built-in + more plumbing
+ run_completion "git g" &&
+ grep gitk out &&
+ grep get-tar-commit-id out
+'
+
test_expect_success '__git_complete' '
unset -f __git_wrap__git_main &&
--
2.35.0.rc2.886.ga87834885e8
next prev parent reply other threads:[~2022-01-25 12:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 8:42 Some sub-commands can't be completed by TAB key Hongyi Zhao
2022-01-22 14:47 ` Johannes Sixt
2022-01-23 0:38 ` Hongyi Zhao
2022-01-23 17:31 ` Philippe Blain
2022-01-23 19:51 ` Junio C Hamano
2022-01-24 1:42 ` Hongyi Zhao
2022-01-24 9:18 ` João Victor Bonfim
2022-01-25 7:33 ` Junio C Hamano
2022-01-25 12:49 ` Ævar Arnfjörð Bjarmason [this message]
2022-01-26 22:34 ` [PATCH] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS Junio C Hamano
2022-02-02 11:15 ` [PATCH v2 0/2] " Ævar Arnfjörð Bjarmason
2022-02-02 11:15 ` [PATCH v2 1/2] completion tests: re-source git-completion.bash in a subshell Ævar Arnfjörð Bjarmason
2022-02-02 11:15 ` [PATCH v2 2/2] completion: add a GIT_COMPLETION_SHOW_ALL_COMMANDS Ævar Arnfjörð Bjarmason
2022-02-06 13:30 ` SZEDER Gábor
2022-02-06 20:09 ` Junio C Hamano
2022-02-06 22:47 ` SZEDER Gábor
2022-02-07 7:03 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-1.1-5f18305ca08-20220125T124757Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=JoaoVictorBonfim+Git-Mail-List@protonmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hongyi.zhao@gmail.com \
--cc=j6t@kdbg.org \
--cc=levraiphilippeblain@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).