threads / patch / 55861

v2, 4 partscompletion: bash: fix for suboptions with value

Subject: [PATCH v2 try2 2/4] completion: bash: fix for suboptions with value

## tl;dr

16 messages between Jun 6, 2021 and Jun 8, 2021. Diffs are folded; open one to read it.

replies: 15people: 4as markdown or json

Felipe Contreras· Jun 6, 2021, 18:47 UTC · lore

[PATCH v2 try2 0/4] completion: bash: a bunch of fixes

These should be pretty obvious and straightforward.

This is the second time I'm sending this exact series, and the seventh time in almost exactly the same form.

The previous version was still applying without conflicts to master, and so does this one.
 * https://lore.kernel.org/git/xmqqv9cavcc5.fsf@gitster.c.googlers.com/
 * https://lore.kernel.org/git/6094a335c22dc_8ee520860@natae.notmuch/
Felipe Contreras (4):
  completion: bash: fix prefix detection in branch.*
  completion: bash: fix for suboptions with value
  completion: bash: fix for multiple dash commands
  completion: bash: add correct suffix in variables
 contrib/completion/git-completion.bash | 14 +++++++-------
 t/t9902-completion.sh                  | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)
Range-diff:
1:  dd49b0e680 ! 1:  52de92cb06 completion: bash: fix prefix detection in branch.*
    @@ Commit message
     
           git clone --config=branch.<tab>
     
    +    Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
2:  6ac184b9a4 = 2:  af2f17364d completion: bash: fix for suboptions with value
3:  960a692fda = 3:  a3bcb70594 completion: bash: fix for multiple dash commands
4:  a95c3edaf9 = 4:  6b3ef41c92 completion: bash: add correct suffix in variables
-- 
2.31.1.2.g0532ba4bf6
Felipe Contreras· Jun 6, 2021, 18:47 UTC · re: Felipe Contreras · lore
We need to ignore options that don't start with -- as well.

Depending on the value of COMP_WORDBREAKS the last word could be duplicated otherwise.

Can be tested with:
  git merge -X diff-algorithm=<tab>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |  2 +-
 t/t9902-completion.sh                  | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
Show changes to 2 files +16 −1

contrib/completion/git-completion.bash, t/t9902-completion.sh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 47b48fbab6..05606609f9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -356,7 +356,7 @@ __gitcomp ()
 	local cur_="${3-$cur}"
 
 	case "$cur_" in
-	--*=)
+	*=)
 		;;
 	--no-*)
 		local c i=0 IFS=$' \t\n'
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index cb057ef161..6b56e54fc3 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -540,6 +540,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '
 	EOF
 '
 
+test_expect_success '__gitcomp - equal skip' '
+	test_gitcomp "--option=" "--option=" <<-\EOF &&
+
+	EOF
+	test_gitcomp "option=" "option=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
 	__gitcomp "$invalid_variable_name"
 '
@@ -2380,6 +2389,12 @@ test_expect_success 'git clone --config= - value' '
 	EOF
 '
 
+test_expect_success 'options with value' '
+	test_completion "git merge -X diff-algorithm=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success 'sourcing the completion script clears cached commands' '
 	__git_compute_all_commands &&
 	verbose test -n "$__git_all_commands" &&
-- 
2.31.1.2.g0532ba4bf6
Felipe Contreras· Jun 6, 2021, 18:47 UTC · re: Felipe Contreras · lore

[PATCH v2 try2 1/4] completion: bash: fix prefix detection in branch.*

Otherwise we are completely ignoring the --cur argument.
The issue can be tested with:
  git clone --config=branch.<tab>
Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to contrib/completion/git-completion.bash +2 −2
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b50c5d0ea3..47b48fbab6 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2649,8 +2649,8 @@ __git_complete_config_variable_name ()
 		return
 		;;
 	branch.*)
-		local pfx="${cur%.*}."
-		cur_="${cur#*.}"
+		local pfx="${cur_%.*}."
+		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
 		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
 		return
-- 
2.31.1.2.g0532ba4bf6
Felipe Contreras· Jun 6, 2021, 18:47 UTC · re: Felipe Contreras · lore

[PATCH v2 try2 3/4] completion: bash: fix for multiple dash commands

Otherwise commands like 'for-each-ref' are not completed.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +1 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 05606609f9..1feb2ee108 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -421,7 +421,7 @@ __gitcomp_builtin ()
 	local incl="${2-}"
 	local excl="${3-}"
 
-	local var=__gitcomp_builtin_"${cmd/-/_}"
+	local var=__gitcomp_builtin_"${cmd//-/_}"
 	local options
 	eval "options=\${$var-}"
 
-- 
2.31.1.2.g0532ba4bf6
SZEDER Gábor· Jun 7, 2021, 19:00 UTC · re: Felipe Contreras · lore

Re: [PATCH v2 try2 3/4] completion: bash: fix for multiple dash commands

On Sun, Jun 06, 2021 at 01:47:25PM -0500, Felipe Contreras wrote:
> Otherwise commands like 'for-each-ref' are not completed.

I think you meant that options of commands like 'for-each-ref' are not completed. The command itself can be completed just fine:

  $ git for<TAB>
  for-each-ref      format-patch      
Show 21 quoted lines
> Signed-off-by: Felipe Contreras <felipe.contreras@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 05606609f9..1feb2ee108 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -421,7 +421,7 @@ __gitcomp_builtin ()
>  	local incl="${2-}"
>  	local excl="${3-}"
>  
> -	local var=__gitcomp_builtin_"${cmd/-/_}"
> +	local var=__gitcomp_builtin_"${cmd//-/_}"
>  	local options
>  	eval "options=\${$var-}"
>  
> -- 
> 2.31.1.2.g0532ba4bf6
> 
Felipe Contreras· Jun 7, 2021, 19:11 UTC · re: SZEDER Gábor · lore

Re: [PATCH v2 try2 3/4] completion: bash: fix for multiple dash commands

SZEDER Gábor wrote:
Show 8 quoted lines
> On Sun, Jun 06, 2021 at 01:47:25PM -0500, Felipe Contreras wrote:
> > Otherwise commands like 'for-each-ref' are not completed.
> 
> I think you meant that options of commands like 'for-each-ref' are not
> completed.  The command itself can be completed just fine:
> 
>   $ git for<TAB>
>   for-each-ref      format-patch      

Yes, I meant commands like 'for-each-ref' are not completed correctly... by __gitcomp_builtin. Which in practical tearms means what you just described above.

-- 
Felipe Contreras
Junio C Hamano· Jun 8, 2021, 05:15 UTC · re: Felipe Contreras · lore

Re: [PATCH v2 try2 3/4] completion: bash: fix for multiple dash commands

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 7 quoted lines
> SZEDER Gábor wrote:
>> On Sun, Jun 06, 2021 at 01:47:25PM -0500, Felipe Contreras wrote:
>> > Otherwise commands like 'for-each-ref' are not completed.
>> 
>> I think you meant that options of commands like 'for-each-ref' are not
>> completed.
>> ...
> Yes, I meant commands like 'for-each-ref' are not completed correctly...
> by __gitcomp_builtin. Which in practical tearms means what you just
> described above.

I couldn't exactly tell if that's a roundabout way to say "yes, yours is better and I'll use it in an update, thanks". I'll assume that is the case and will mark the topic as expecting the final update (as it seemed that all the other patches in the series were received favourably).

Or was it meant as "no, the version you commented on was already correct (if you squint your eyes)"?

Thanks.
Felipe Contreras· Jun 8, 2021, 05:49 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 try2 3/4] completion: bash: fix for multiple dash commands

Junio C Hamano wrote:
Show 16 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
> 
> > SZEDER Gábor wrote:
> >> On Sun, Jun 06, 2021 at 01:47:25PM -0500, Felipe Contreras wrote:
> >> > Otherwise commands like 'for-each-ref' are not completed.
> >> 
> >> I think you meant that options of commands like 'for-each-ref' are not
> >> completed.
> >> ...
> 
> > Yes, I meant commands like 'for-each-ref' are not completed correctly...
> > by __gitcomp_builtin. Which in practical tearms means what you just
> > described above.
> 
> I couldn't exactly tell if that's a roundabout way to say "yes,
> yours is better and I'll use it in an update, thanks".
I meant that I meant what he said I meant.

But meaning is not saying, and it's better to say what one means (implied), and since Szeder's version says what I meant, that's better.

> I'll assume that is the case and will mark the topic as expecting the
> final update (as it seemed that all the other patches in the series
> were received favourably).

I think it would be trivial to do s/commands/options of &/ when merging the series, but fine, I'll reroll.

> Or was it meant as "no, the version you commented on was already
> correct (if you squint your eyes)"?
No, that's not what I meant.
-- 
Felipe Contreras
Felipe Contreras· Jun 6, 2021, 18:47 UTC · re: Felipe Contreras · lore

[PATCH v2 try2 4/4] completion: bash: add correct suffix in variables

__gitcomp automatically adds a suffix, but __gitcomp_nl and others don't, we need to specify a space by default.

Can be tested with:
  git config branch.autoSetupMe<tab>

This fix only works for versions of bash greater than 4.0, before that "local sfx" creates an empty string, therefore the unset expansion doesn't work. The same happens in zsh.

Therefore we don't add the test for that for now.

The correct fix for all shells requires semantic changes in __gitcomp, but that can be done later.

Cc: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to contrib/completion/git-completion.bash +3 −3
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1feb2ee108..c72b5465f9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2652,7 +2652,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	guitool.*.*)
@@ -2686,7 +2686,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__git_compute_all_commands
-		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	remote.*.*)
@@ -2702,7 +2702,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	url.*.*)
-- 
2.31.1.2.g0532ba4bf6
David Aguilar· Jun 7, 2021, 00:46 UTC · re: Felipe Contreras · lore

Re: [PATCH v2 try2 0/4] completion: bash: a bunch of fixes

On Sun, Jun 6, 2021 at 11:51 AM Felipe Contreras <felipe.contreras@gmail.com> wrote:

Show 37 quoted lines
>
> These should be pretty obvious and straightforward.
>
> This is the second time I'm sending this exact series, and the seventh time in almost
> exactly the same form.
>
> The previous version was still applying without conflicts to master, and so does this one.
>
>  * https://lore.kernel.org/git/xmqqv9cavcc5.fsf@gitster.c.googlers.com/
>  * https://lore.kernel.org/git/6094a335c22dc_8ee520860@natae.notmuch/
>
> Felipe Contreras (4):
>   completion: bash: fix prefix detection in branch.*
>   completion: bash: fix for suboptions with value
>   completion: bash: fix for multiple dash commands
>   completion: bash: add correct suffix in variables
>
>  contrib/completion/git-completion.bash | 14 +++++++-------
>  t/t9902-completion.sh                  | 15 +++++++++++++++
>  2 files changed, 22 insertions(+), 7 deletions(-)
>
> Range-diff:
> 1:  dd49b0e680 ! 1:  52de92cb06 completion: bash: fix prefix detection in branch.*
>     @@ Commit message
>
>            git clone --config=branch.<tab>
>
>     +    Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
>          Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
>
>       ## contrib/completion/git-completion.bash ##
> 2:  6ac184b9a4 = 2:  af2f17364d completion: bash: fix for suboptions with value
> 3:  960a692fda = 3:  a3bcb70594 completion: bash: fix for multiple dash commands
> 4:  a95c3edaf9 = 4:  6b3ef41c92 completion: bash: add correct suffix in variables
> --
> 2.31.1.2.g0532ba4bf6
>
I tested this series on:
- GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
- GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
- zsh 5.0.2 (x86_64-redhat-linux-gnu)
- zsh 5.7.1 (x86_64-apple-darwin19.0)
and can confirm that it is an improvement.
FWIW,
Tested-by: David Aguilar <davvid@gmail.com>
cheers,
-- 
David
Junio C Hamano· Jun 7, 2021, 01:08 UTC · re: David Aguilar · lore

Re: [PATCH v2 try2 0/4] completion: bash: a bunch of fixes

David Aguilar <davvid@gmail.com> writes:
Show 11 quoted lines
> On Sun, Jun 6, 2021 at 11:51 AM Felipe Contreras
> ...
> I tested this series on:
> - GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
> - GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
> - zsh 5.0.2 (x86_64-redhat-linux-gnu)
> - zsh 5.7.1 (x86_64-apple-darwin19.0)
> and can confirm that it is an improvement.
>
> FWIW,
> Tested-by: David Aguilar <davvid@gmail.com>

Thanks, will queue (I haven't checked if there is any overlap with what is cooking above 'master', so it may not happen very soon, though).

Felipe Contreras· Jun 8, 2021, 06:00 UTC · re: Felipe Contreras · lore

[PATCH v3 0/4] completion: bash: a bunch of fixes

These should be pretty obvious and straightforward.

Since v2 only a commit message was updated to say "options of commands" insead of "commands".

Felipe Contreras (4):
  completion: bash: fix prefix detection in branch.*
  completion: bash: fix for suboptions with value
  completion: bash: fix for multiple dash commands
  completion: bash: add correct suffix in variables
 contrib/completion/git-completion.bash | 14 +++++++-------
 t/t9902-completion.sh                  | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 7 deletions(-)
Range-diff:
1:  52de92cb06 ! 1:  4b73b26338 completion: bash: fix prefix detection in branch.*
    @@ Commit message
           git clone --config=branch.<tab>
     
         Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
    +    Tested-by: David Aguilar <davvid@gmail.com>
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
2:  af2f17364d ! 2:  cb2fc1a7f2 completion: bash: fix for suboptions with value
    @@ Commit message
     
           git merge -X diff-algorithm=<tab>
     
    +    Tested-by: David Aguilar <davvid@gmail.com>
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
3:  a3bcb70594 ! 3:  ece06463a2 completion: bash: fix for multiple dash commands
    @@ Metadata
      ## Commit message ##
         completion: bash: fix for multiple dash commands
     
    -    Otherwise commands like 'for-each-ref' are not completed.
    +    Otherwise options of commands like 'for-each-ref' are not completed.
     
    +    Tested-by: David Aguilar <davvid@gmail.com>
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
4:  6b3ef41c92 ! 4:  f9db132cbd completion: bash: add correct suffix in variables
    @@ Commit message
         but that can be done later.
     
         Cc: SZEDER Gábor <szeder.dev@gmail.com>
    +    Tested-by: David Aguilar <davvid@gmail.com>
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
-- 
2.32.0.2.g41be0a4e50
Felipe Contreras· Jun 8, 2021, 06:00 UTC · re: Felipe Contreras · lore

[PATCH v3 2/4] completion: bash: fix for suboptions with value

We need to ignore options that don't start with -- as well.

Depending on the value of COMP_WORDBREAKS the last word could be duplicated otherwise.

Can be tested with:
  git merge -X diff-algorithm=<tab>
Tested-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |  2 +-
 t/t9902-completion.sh                  | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
Show changes to 2 files +16 −1

contrib/completion/git-completion.bash, t/t9902-completion.sh

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 47b48fbab6..05606609f9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -356,7 +356,7 @@ __gitcomp ()
 	local cur_="${3-$cur}"
 
 	case "$cur_" in
-	--*=)
+	*=)
 		;;
 	--no-*)
 		local c i=0 IFS=$' \t\n'
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index cb057ef161..6b56e54fc3 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -540,6 +540,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '
 	EOF
 '
 
+test_expect_success '__gitcomp - equal skip' '
+	test_gitcomp "--option=" "--option=" <<-\EOF &&
+
+	EOF
+	test_gitcomp "option=" "option=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '
 	__gitcomp "$invalid_variable_name"
 '
@@ -2380,6 +2389,12 @@ test_expect_success 'git clone --config= - value' '
 	EOF
 '
 
+test_expect_success 'options with value' '
+	test_completion "git merge -X diff-algorithm=" <<-\EOF
+
+	EOF
+'
+
 test_expect_success 'sourcing the completion script clears cached commands' '
 	__git_compute_all_commands &&
 	verbose test -n "$__git_all_commands" &&
-- 
2.32.0.2.g41be0a4e50
Felipe Contreras· Jun 8, 2021, 06:00 UTC · re: Felipe Contreras · lore

[PATCH v3 3/4] completion: bash: fix for multiple dash commands

Otherwise options of commands like 'for-each-ref' are not completed.
Tested-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +1 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 05606609f9..1feb2ee108 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -421,7 +421,7 @@ __gitcomp_builtin ()
 	local incl="${2-}"
 	local excl="${3-}"
 
-	local var=__gitcomp_builtin_"${cmd/-/_}"
+	local var=__gitcomp_builtin_"${cmd//-/_}"
 	local options
 	eval "options=\${$var-}"
 
-- 
2.32.0.2.g41be0a4e50
Felipe Contreras· Jun 8, 2021, 06:00 UTC · re: Felipe Contreras · lore

[PATCH v3 1/4] completion: bash: fix prefix detection in branch.*

Otherwise we are completely ignoring the --cur argument.
The issue can be tested with:
  git clone --config=branch.<tab>
Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
Tested-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to contrib/completion/git-completion.bash +2 −2
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b50c5d0ea3..47b48fbab6 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2649,8 +2649,8 @@ __git_complete_config_variable_name ()
 		return
 		;;
 	branch.*)
-		local pfx="${cur%.*}."
-		cur_="${cur#*.}"
+		local pfx="${cur_%.*}."
+		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
 		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
 		return
-- 
2.32.0.2.g41be0a4e50
Felipe Contreras· Jun 8, 2021, 06:00 UTC · re: Felipe Contreras · lore

[PATCH v3 4/4] completion: bash: add correct suffix in variables

__gitcomp automatically adds a suffix, but __gitcomp_nl and others don't, we need to specify a space by default.

Can be tested with:
  git config branch.autoSetupMe<tab>

This fix only works for versions of bash greater than 4.0, before that "local sfx" creates an empty string, therefore the unset expansion doesn't work. The same happens in zsh.

Therefore we don't add the test for that for now.

The correct fix for all shells requires semantic changes in __gitcomp, but that can be done later.

Cc: SZEDER Gábor <szeder.dev@gmail.com>
Tested-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to contrib/completion/git-completion.bash +3 −3
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1feb2ee108..c72b5465f9 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2652,7 +2652,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	guitool.*.*)
@@ -2686,7 +2686,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__git_compute_all_commands
-		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	remote.*.*)
@@ -2702,7 +2702,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
+		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	url.*.*)
-- 
2.32.0.2.g41be0a4e50

← back to recent threads