git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] completion: fix completing unstuck email alias arguments
@ 2015-12-12  0:18 SZEDER Gábor
  2015-12-12  1:56 ` Jacob Keller
  0 siblings, 1 reply; 3+ messages in thread
From: SZEDER Gábor @ 2015-12-12  0:18 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Jacob Keller, git, SZEDER Gábor

Completing unstuck form of email aliases doesn't quite work:

  $ git send-email --to <TAB>
  alice   bob     cecil
  $ git send-email --to a<TAB>
  alice   bob     cecil

While listing email aliases works as expected, the second case should
just complete to 'alice', but it keeps offering all email aliases
instead.

The cause for this behavior is that in this case we mistakenly tell
__gitcomp() explicitly that the current word to be completed is empty,
while in reality it is not.  As a result __gitcomp() doesn't filter
out non-matching aliases, so all aliases end up being offered over and
over again.

Fix this by not passing the current word to be completed to
__gitcomp() and letting it go the default route and grab it from the
'$cur' variable.  Don't pass empty prefix either, because it's assumed
to be empty when unspecified, so it's not necessary.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---

On top of the recently merged dfbe5eeb32 (completion: add support for
completing email aliases, 2015-11-19).

 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 111b05302b..d9b995799c 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1716,7 +1716,7 @@ _git_send_email ()
 	--to|--cc|--bcc|--from)
 		__gitcomp "
 		$(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
-		" "" ""
+		"
 		return
 		;;
 	esac
-- 
2.7.0.rc0.37.g77d69b9

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

* Re: [PATCH] completion: fix completing unstuck email alias arguments
  2015-12-12  0:18 [PATCH] completion: fix completing unstuck email alias arguments SZEDER Gábor
@ 2015-12-12  1:56 ` Jacob Keller
  2015-12-13  1:00   ` SZEDER Gábor
  0 siblings, 1 reply; 3+ messages in thread
From: Jacob Keller @ 2015-12-12  1:56 UTC (permalink / raw
  To: SZEDER Gábor; +Cc: Junio C Hamano, Git mailing list

On Fri, Dec 11, 2015 at 4:18 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
> Completing unstuck form of email aliases doesn't quite work:
>
>   $ git send-email --to <TAB>
>   alice   bob     cecil
>   $ git send-email --to a<TAB>
>   alice   bob     cecil
>

Woops. Is it possible to add a test for this case? I honestly don't
know how the tests for the completion works.

> While listing email aliases works as expected, the second case should
> just complete to 'alice', but it keeps offering all email aliases
> instead.
>
> The cause for this behavior is that in this case we mistakenly tell
> __gitcomp() explicitly that the current word to be completed is empty,
> while in reality it is not.  As a result __gitcomp() doesn't filter
> out non-matching aliases, so all aliases end up being offered over and
> over again.
>
> Fix this by not passing the current word to be completed to
> __gitcomp() and letting it go the default route and grab it from the
> '$cur' variable.  Don't pass empty prefix either, because it's assumed
> to be empty when unspecified, so it's not necessary.
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
>
> On top of the recently merged dfbe5eeb32 (completion: add support for
> completing email aliases, 2015-11-19).
>
>  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 111b05302b..d9b995799c 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1716,7 +1716,7 @@ _git_send_email ()
>         --to|--cc|--bcc|--from)
>                 __gitcomp "
>                 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
> -               " "" ""
> +               "

Yes this looks reasonable to me.

>                 return
>                 ;;
>         esac
> --
> 2.7.0.rc0.37.g77d69b9
>

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

* Re: [PATCH] completion: fix completing unstuck email alias arguments
  2015-12-12  1:56 ` Jacob Keller
@ 2015-12-13  1:00   ` SZEDER Gábor
  0 siblings, 0 replies; 3+ messages in thread
From: SZEDER Gábor @ 2015-12-13  1:00 UTC (permalink / raw
  To: Jacob Keller; +Cc: Junio C Hamano, Git mailing list


Quoting Jacob Keller <jacob.keller@gmail.com>:

> On Fri, Dec 11, 2015 at 4:18 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
>> Completing unstuck form of email aliases doesn't quite work:
>>
>> $ git send-email --to <TAB>
>> alice   bob     cecil
>> $ git send-email --to a<TAB>
>> alice   bob     cecil
>>
>
> Woops. Is it possible to add a test for this case? I honestly don't
> know how the tests for the completion works.

It's possible, but I'm not sure we should.

It's a common pattern throughout the completion script to call
__gitcomp() (or __gitcomp_nl()) this way, out of the almost 200
callsites many look like this one.  We don't test all those, because
it would require a lot of tests for not that much gain in coverage
in my opinion.  The interesting thing that's definitely worth testing
is what happens inside the command substitution that supplies the
possible completion words, but your tests added to the send-email
testsuite already cover that thoroughly.

Gábor

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

end of thread, other threads:[~2015-12-13  1:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-12  0:18 [PATCH] completion: fix completing unstuck email alias arguments SZEDER Gábor
2015-12-12  1:56 ` Jacob Keller
2015-12-13  1:00   ` 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).