All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 try4 0/4] completion: bash: a bunch of fixes
@ 2021-08-16  9:10 Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 1/4] completion: bash: fix prefix detection in branch.* Felipe Contreras
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Felipe Contreras @ 2021-08-16  9:10 UTC (permalink / raw)
  To: git; +Cc: David Aguilar, Felipe Contreras

These should be pretty obvious and straightforward.

This is exactly the same as v3, which has been sent 4 times, and already
included the minor adjustment to the commit message of one patch as
suggested by SZEDER Gábor, which was done nine minutes after in June 8,
but for some reason they had trouble getting into 'seen'. So I'm sending
it yet again.

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:  4b73b26338 = 1:  e699c8be36 completion: bash: fix prefix detection in branch.*
2:  cb2fc1a7f2 = 2:  7e800faaf1 completion: bash: fix for suboptions with value
3:  ece06463a2 = 3:  523906fe1a completion: bash: fix for multiple dash commands
4:  f9db132cbd = 4:  1cb7457af9 completion: bash: add correct suffix in variables
-- 
2.32.0.48.g096519100f


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

* [PATCH v3 try4 1/4] completion: bash: fix prefix detection in branch.*
  2021-08-16  9:10 [PATCH v3 try4 0/4] completion: bash: a bunch of fixes Felipe Contreras
@ 2021-08-16  9:10 ` Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 2/4] completion: bash: fix for suboptions with value Felipe Contreras
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Felipe Contreras @ 2021-08-16  9:10 UTC (permalink / raw)
  To: git; +Cc: David Aguilar, Felipe Contreras

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(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4bdd27ddc8..6bcf97ce79 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2650,8 +2650,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.48.g096519100f


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

* [PATCH v3 try4 2/4] completion: bash: fix for suboptions with value
  2021-08-16  9:10 [PATCH v3 try4 0/4] completion: bash: a bunch of fixes Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 1/4] completion: bash: fix prefix detection in branch.* Felipe Contreras
@ 2021-08-16  9:10 ` Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 3/4] completion: bash: fix for multiple dash commands Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 4/4] completion: bash: add correct suffix in variables Felipe Contreras
  3 siblings, 0 replies; 5+ messages in thread
From: Felipe Contreras @ 2021-08-16  9:10 UTC (permalink / raw)
  To: git; +Cc: David Aguilar, Felipe Contreras

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(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6bcf97ce79..7aea1abda5 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.48.g096519100f


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

* [PATCH v3 try4 3/4] completion: bash: fix for multiple dash commands
  2021-08-16  9:10 [PATCH v3 try4 0/4] completion: bash: a bunch of fixes Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 1/4] completion: bash: fix prefix detection in branch.* Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 2/4] completion: bash: fix for suboptions with value Felipe Contreras
@ 2021-08-16  9:10 ` Felipe Contreras
  2021-08-16  9:10 ` [PATCH v3 try4 4/4] completion: bash: add correct suffix in variables Felipe Contreras
  3 siblings, 0 replies; 5+ messages in thread
From: Felipe Contreras @ 2021-08-16  9:10 UTC (permalink / raw)
  To: git; +Cc: David Aguilar, Felipe Contreras

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(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7aea1abda5..b7988f0485 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.48.g096519100f


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

* [PATCH v3 try4 4/4] completion: bash: add correct suffix in variables
  2021-08-16  9:10 [PATCH v3 try4 0/4] completion: bash: a bunch of fixes Felipe Contreras
                   ` (2 preceding siblings ...)
  2021-08-16  9:10 ` [PATCH v3 try4 3/4] completion: bash: fix for multiple dash commands Felipe Contreras
@ 2021-08-16  9:10 ` Felipe Contreras
  3 siblings, 0 replies; 5+ messages in thread
From: Felipe Contreras @ 2021-08-16  9:10 UTC (permalink / raw)
  To: git; +Cc: David Aguilar, Felipe Contreras

__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(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b7988f0485..8108eda1e8 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2653,7 +2653,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.*.*)
@@ -2687,7 +2687,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.*.*)
@@ -2703,7 +2703,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.48.g096519100f


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

end of thread, other threads:[~2021-08-16  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16  9:10 [PATCH v3 try4 0/4] completion: bash: a bunch of fixes Felipe Contreras
2021-08-16  9:10 ` [PATCH v3 try4 1/4] completion: bash: fix prefix detection in branch.* Felipe Contreras
2021-08-16  9:10 ` [PATCH v3 try4 2/4] completion: bash: fix for suboptions with value Felipe Contreras
2021-08-16  9:10 ` [PATCH v3 try4 3/4] completion: bash: fix for multiple dash commands Felipe Contreras
2021-08-16  9:10 ` [PATCH v3 try4 4/4] completion: bash: add correct suffix in variables Felipe Contreras

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.