From: Junio C Hamano <gitster@pobox.com>
To: "Jean-Noël AVILA" <jn.avila@free.fr>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH] t9902: Instruct git-completion.bash about a test mode
Date: Thu, 24 Jan 2013 13:46:13 -0800 [thread overview]
Message-ID: <7vtxq68day.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <201301242220.09067.jn.avila@free.fr> ("Jean-Noël AVILA"'s message of "Thu, 24 Jan 2013 22:20:08 +0100")
"Jean-Noël AVILA" <jn.avila@free.fr> writes:
> In test mode, git completion should propose commands only if they
> belong to the list of authorized commands.
>
> Signed-off-by: Jean-Noel Avila <jn.avila@free.fr>
> ---
>
> Better show some code than try to explain. Here is what I mean by
> "filter the output git help -a".
Why do you have to make an extra shell function call for each and
every possible Git subcommand to slow down everybody's work when not
in testing mode?
Comparing it with Peff's suggestion, it is fairly clear which one we
should pick, I think.
> contrib/completion/git-completion.bash | 16 +++++++++++++++-
> t/t9902-completion.sh | 4 ++--
> 2 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 14dd5e7..6490553 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -531,6 +531,20 @@ __git_complete_strategy ()
> return 1
> }
>
> +if test -z "$AUTHORIZED_CMD_LIST"; then
> + __git_cmdlist ()
> + {
> + echo $1;
> + }
> +else
> + __git_cmdlist ()
> + {
> + if [[ " $AUTHORIZED_CMD_LIST " =~ " $1 " ]] ; then
> + echo $1
> + fi
> + }
> +fi
> +
> __git_list_all_commands ()
> {
> local i IFS=" "$'\n'
> @@ -538,7 +552,7 @@ __git_list_all_commands ()
> do
> case $i in
> *--*) : helper pattern;;
> - *) echo $i;;
> + *) __git_cmdlist $i;;
> esac
> done
> }
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 3cd53f8..5e7d81e 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -12,8 +12,8 @@ complete ()
> # do nothing
> return 0
> }
> -
> -. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
> +AUTHORIZED_CMD_LIST=" checkout show add filter-branch ls-files send-email describe"
> +. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
>
> # We don't need this function to actually join words or do anything special.
> # Also, it's cleaner to avoid touching bash's internal completion variables.
next prev parent reply other threads:[~2013-01-24 21:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-24 21:20 [PATCH] t9902: Instruct git-completion.bash about a test mode Jean-Noël AVILA
2013-01-24 21:46 ` Junio C Hamano [this message]
2013-01-24 22:04 ` Jean-Noël AVILA
2013-01-24 22:29 ` Junio C Hamano
2013-01-24 22:56 ` Jean-Noël AVILA
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=7vtxq68day.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jn.avila@free.fr \
--cc=peff@peff.net \
/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