git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] completion: fix __gitcomp_builtin no longer consider extra options
@ 2018-10-21  8:37 Nguyễn Thái Ngọc Duy
  2018-10-22  3:51 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2018-10-21  8:37 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

__gitcomp_builtin() has the main completion list provided by

    git xxx --git-completion-helper

but the caller can also add extra options that is not provided by
--git-completion-helper. The only call site that does this is "git
difftool" completion.

This support is broken by b221b5ab9b (completion: collapse extra
--no-.. options - 2018-06-06), which adds a special value "--" to mark
that the rest of the options can be hidden by default. The commit
forgets the fact that extra options are appended after
"$(git xxx --git-completion-helper)", i.e. after this "--", and will
be incorrectly hidden as well.

Prepend the extra options before "$(git xxx --git-completion-helper)"
to avoid this.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index db7fd87b6b..c8fdcf8644 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -400,7 +400,7 @@ __gitcomp_builtin ()
 	if [ -z "$options" ]; then
 		# leading and trailing spaces are significant to make
 		# option removal work correctly.
-		options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
+		options=" $incl $(__git ${cmd/_/ } --git-completion-helper) "
 		for i in $excl; do
 			options="${options/ $i / }"
 		done
-- 
2.19.1.647.g708186aaf9


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion: fix __gitcomp_builtin no longer consider extra options
  2018-10-21  8:37 [PATCH] completion: fix __gitcomp_builtin no longer consider extra options Nguyễn Thái Ngọc Duy
@ 2018-10-22  3:51 ` Junio C Hamano
  2018-10-22 14:34   ` Duy Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2018-10-22  3:51 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> __gitcomp_builtin() has the main completion list provided by
>
>     git xxx --git-completion-helper
>
> but the caller can also add extra options that is not provided by
> --git-completion-helper. The only call site that does this is "git
> difftool" completion.
>
> This support is broken by b221b5ab9b (completion: collapse extra
> --no-.. options - 2018-06-06), which adds a special value "--" to mark
> that the rest of the options can be hidden by default. The commit
> forgets the fact that extra options are appended after
> "$(git xxx --git-completion-helper)", i.e. after this "--", and will
> be incorrectly hidden as well.
>
> Prepend the extra options before "$(git xxx --git-completion-helper)"
> to avoid this.

Thanks for a clear analysis.  How did you find it?  Got annoyed that
completion of difftool got broken, or discovered while trying to
apply the same trick as difftool completion uses to another one and
seeing that the technique does not work?

Will queue.  Thanks.

>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index db7fd87b6b..c8fdcf8644 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -400,7 +400,7 @@ __gitcomp_builtin ()
>  	if [ -z "$options" ]; then
>  		# leading and trailing spaces are significant to make
>  		# option removal work correctly.
> -		options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
> +		options=" $incl $(__git ${cmd/_/ } --git-completion-helper) "
>  		for i in $excl; do
>  			options="${options/ $i / }"
>  		done

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion: fix __gitcomp_builtin no longer consider extra options
  2018-10-22  3:51 ` Junio C Hamano
@ 2018-10-22 14:34   ` Duy Nguyen
  2018-10-22 17:49     ` SZEDER Gábor
  0 siblings, 1 reply; 4+ messages in thread
From: Duy Nguyen @ 2018-10-22 14:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

On Mon, Oct 22, 2018 at 5:51 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
> > __gitcomp_builtin() has the main completion list provided by
> >
> >     git xxx --git-completion-helper
> >
> > but the caller can also add extra options that is not provided by
> > --git-completion-helper. The only call site that does this is "git
> > difftool" completion.
> >
> > This support is broken by b221b5ab9b (completion: collapse extra
> > --no-.. options - 2018-06-06), which adds a special value "--" to mark
> > that the rest of the options can be hidden by default. The commit
> > forgets the fact that extra options are appended after
> > "$(git xxx --git-completion-helper)", i.e. after this "--", and will
> > be incorrectly hidden as well.
> >
> > Prepend the extra options before "$(git xxx --git-completion-helper)"
> > to avoid this.
>
> Thanks for a clear analysis.  How did you find it?  Got annoyed that
> completion of difftool got broken, or discovered while trying to
> apply the same trick as difftool completion uses to another one and
> seeing that the technique does not work?

I was fixing format-patch completion and was surprised it did not work
as expected. Never really used difftool myself :P I only found out
about it when I asked myself "why wasn't this breakage found earlier?"
-- 
Duy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion: fix __gitcomp_builtin no longer consider extra options
  2018-10-22 14:34   ` Duy Nguyen
@ 2018-10-22 17:49     ` SZEDER Gábor
  0 siblings, 0 replies; 4+ messages in thread
From: SZEDER Gábor @ 2018-10-22 17:49 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Junio C Hamano, Git Mailing List

On Mon, Oct 22, 2018 at 04:34:16PM +0200, Duy Nguyen wrote:
> On Mon, Oct 22, 2018 at 5:51 AM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> >
> > > __gitcomp_builtin() has the main completion list provided by
> > >
> > >     git xxx --git-completion-helper
> > >
> > > but the caller can also add extra options that is not provided by
> > > --git-completion-helper. The only call site that does this is "git
> > > difftool" completion.
> > >
> > > This support is broken by b221b5ab9b (completion: collapse extra
> > > --no-.. options - 2018-06-06), which adds a special value "--" to mark
> > > that the rest of the options can be hidden by default. The commit
> > > forgets the fact that extra options are appended after
> > > "$(git xxx --git-completion-helper)", i.e. after this "--", and will
> > > be incorrectly hidden as well.
> > >
> > > Prepend the extra options before "$(git xxx --git-completion-helper)"
> > > to avoid this.
> >
> > Thanks for a clear analysis.  How did you find it?  Got annoyed that
> > completion of difftool got broken, or discovered while trying to
> > apply the same trick as difftool completion uses to another one and
> > seeing that the technique does not work?
> 
> I was fixing format-patch completion and was surprised it did not work
> as expected. Never really used difftool myself :P I only found out
> about it when I asked myself "why wasn't this breakage found earlier?"

Erm...  maybe because there are no tests covering the combination of
extra options and '--no-..' options in 't9902-completion.sh'?

(Hint, hint... :)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-22 17:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-21  8:37 [PATCH] completion: fix __gitcomp_builtin no longer consider extra options Nguyễn Thái Ngọc Duy
2018-10-22  3:51 ` Junio C Hamano
2018-10-22 14:34   ` Duy Nguyen
2018-10-22 17:49     ` SZEDER Gábor

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).