From bf8ae49a8f7d8b6dd87bbea34e6566e8581ab231 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 16 Aug 2021 04:10:22 -0500 Subject: completion: bash: fix prefix detection in branch.* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we are completely ignoring the --cur argument. The issue can be tested with: git clone --config=branch. Reviewed-by: SZEDER Gábor Tested-by: David Aguilar Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib') 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 -- cgit v1.2.3 From e9f2118ddfad4ae5e37adc7637acc9daf4ac8c9c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 16 Aug 2021 04:10:23 -0500 Subject: 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= Tested-by: David Aguilar Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') 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' -- cgit v1.2.3 From f3cc916acc2e0f92c05e07c82c83b370e7d31247 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 16 Aug 2021 04:10:24 -0500 Subject: completion: bash: fix for multiple dash commands Otherwise options of commands like 'for-each-ref' are not completed. Tested-by: David Aguilar Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') 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-}" -- cgit v1.2.3 From be6444d1ca96fdd702b383de860e243aa7e65619 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 16 Aug 2021 04:10:25 -0500 Subject: completion: bash: add correct suffix in variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __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 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 Tested-by: David Aguilar Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib') 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.*.*) -- cgit v1.2.3