{"thread":{"id":"54913","subject":"[PATCH 06/47] test: completion: fix currently typed words","startedAt":"2021-01-01T02:17:23Z","lastAt":"2021-01-01T02:18:22Z","messageCount":48,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":47},"messages":[{"id":"413229","messageId":"20210101021622.798041-7-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 06/47] test: completion: fix currently typed words","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:41Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"They don't match what we are supposed to be completing.\n\nNo functional change.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 39760293f6..05469f04aa 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -486,7 +486,7 @@ test_expect_success '__gitcomp - option parameter' '\n '\n \n test_expect_success '__gitcomp - prefix' '\n-\ttest_gitcomp \"branch.me\" \"remote merge mergeoptions rebase\" \\\n+\ttest_gitcomp \"branch.maint.me\" \"remote merge mergeoptions rebase\" \\\n \t\t\"branch.maint.\" \"me\" <<-\\EOF\n \tbranch.maint.merge Z\n \tbranch.maint.mergeoptions Z\n@@ -494,7 +494,7 @@ test_expect_success '__gitcomp - prefix' '\n '\n \n test_expect_success '__gitcomp - suffix' '\n-\ttest_gitcomp \"branch.me\" \"master maint next seen\" \"branch.\" \\\n+\ttest_gitcomp \"branch.ma\" \"master maint next seen\" \"branch.\" \\\n \t\t\"ma\" \".\" <<-\\EOF\n \tbranch.master.Z\n \tbranch.maint.Z\n-- \n2.30.0\n\n"},{"id":"413230","messageId":"20210101021622.798041-6-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 05/47] completion: bash: do not modify COMP_WORDBREAKS","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:40Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There was no need for this once __git_reassemble_comp_words_by_ref() was\nintroduced. Now irrespective of the value of COMP_WORDBREAKS, words are\nalways joined together.\n\nBy default COMP_WORDBREAKS does contain a colon, and if it doesn't\nsomebody probably has a reason for it.\n\nCompletions are not supposed to modify COMP_WORDBREAKS and none of the\ncompletions in the bash-completion project do.\n\nWe manually set it in Zsh so the Bash script is not confused.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 5 -----\n contrib/completion/git-completion.zsh  | 1 +\n 2 files changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 926e9ceb56..9ea31f7d4d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -45,11 +45,6 @@\n #     When set to \"1\" suggest all options, including options which are\n #     typically hidden (e.g. '--allow-empty' for 'git commit').\n \n-case \"$COMP_WORDBREAKS\" in\n-*:*) : great ;;\n-*)   COMP_WORDBREAKS=\"$COMP_WORDBREAKS:\"\n-esac\n-\n # Discovers the path to the git repository taking any '--git-dir=<path>' and\n # '-C <path>' options into account and stores it in the $__git_repo_path\n # variable.\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 69f90913db..e2ea14fb33 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -45,6 +45,7 @@ fi\n \n local old_complete=\"$functions[complete]\"\n functions[complete]=:\n+COMP_WORDBREAKS=':'\n GIT_SOURCING_ZSH_COMPLETION=y . \"$script\"\n functions[complete]=\"$old_complete\"\n \n-- \n2.30.0\n\n"},{"id":"413231","messageId":"20210101021622.798041-16-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 15/47] completion: zsh: fix for undefined completions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:50Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The parseopt helper can generate the completions even if the function is\nunspecified.\n\n  git version --<tab>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex a9177c7dcb..46564126e4 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -140,6 +140,9 @@ __git_complete_command ()\n \tif (( $+functions[$completion_func] )); then\n \t\temulate ksh -c $completion_func\n \t\treturn 0\n+\telif emulate ksh -c \"__git_support_parseopt_helper $command\"; then\n+\t\temulate ksh -c \"__git_complete_common $command\"\n+\t\treturn 0\n \telse\n \t\treturn 1\n \tfi\n-- \n2.30.0\n\n"},{"id":"413232","messageId":"20210101021622.798041-1-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":null,"subject":"[PATCH 00/47] completion: git-completion 1.3 patches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:35Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"These patches represent what comprises git-completion 1.3, a friendly\nfork I'm maintaining.\n\nSome of these have already been sent, and should be in \"seen\", but for\nsome reason they are not [1]. Others have been sent, but probably won't\nreceive any review soon. And others, particularly zsh improvements,\nhaven't been sent before.\n\nA summary:\n\n * Tons of bugfixes\n * zsh: a bunch of improvements\n * zsh: an important fix regarding quoting\n * zsh: automatic suffix removal\n\nThe rest is reorganization, but it's still much needed.\n\nI'm not anticipating these patches to be merged, I'm providing them in\ncase somebody is interested.\n\n[1] https://lore.kernel.org/git/5fea87e816fff_23821208d4@natae.notmuch/\n\nFelipe Contreras (47):\n  completion: bash: fix prefix detection in branch.*\n  completion: fix for suboptions with value\n  completion: bash: fix for multiple dash commands\n  completion: bash: add correct suffix in variables\n  completion: bash: do not modify COMP_WORDBREAKS\n  test: completion: fix currently typed words\n  test: completion: switch __gitcomp_nl prefix test\n  test: completion: add run_func() helper\n  completion: bash: remove non-append functionality\n  completion: bash: get rid of _append() functions\n  completion: bash: get rid of any non-append code\n  completion: zsh: fix options with arguments\n  completion: zsh: expand --git-dir file argument\n  completion: zsh: add support for general -C opts\n  completion: zsh: fix for undefined completions\n  completion: zsh: add support for general -c opts\n  completion: zsh: fix extra space on foo=\n  completion: zsh: add excluded options\n  completion: zsh: always set compset\n  completion: factor out check in __gitcomp\n  completion: simplify equal suffix check\n  completion: refactor __gitcomp\n  completion: simplify __gitcomp\n  completion: bash: change suffix check in __gitcomp\n  completion: improve __gitcomp suffix code\n  completion: bash: simplify config_variable_name\n  test: completion: add missing test\n  completion: bash: improve __gitcomp description\n  completion: add __gitcomp_opts\n  completion: bash: cleanup __gitcomp* invocations\n  completion: bash: shuffle __gitcomp functions\n  completion: zsh: simplify __gitcomp_direct\n  completion: zsh: shuffle __gitcomp* functions\n  completion: zsh: fix direct quoting\n  completion: zsh: add elements individually in __gitcomp_opts\n  completion: zsh: add __gitcompadd helper\n  completion: zsh: add correct removable suffix\n  completion: bash: simplify _get_comp_words_by_ref()\n  completion: bash: refactor _get_comp_words_by_ref()\n  completion: bash: cleanup _get_comp_words_by_ref()\n  completion: bash: trivial cleanup\n  completion: bash: rename _get_comp_words_by_ref()\n  completion: bash: add __git_have_func helper\n  completion: bash: improve function detection\n  test: completion: add tests for __git_complete\n  completion: add proper public __git_complete\n  completion: zsh: add higher-priority location\n\n contrib/completion/git-completion.bash | 704 ++++++++++++-------------\n contrib/completion/git-completion.zsh  | 133 +++--\n t/t9902-completion.sh                  | 179 ++++---\n 3 files changed, 498 insertions(+), 518 deletions(-)\n\n-- \n2.30.0\n\n"},{"id":"413233","messageId":"20210101021622.798041-3-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 02/47] completion: fix for suboptions with value","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:37Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We need to ignore options that don't start with -- as well.\n\nDepending on the value of COMP_WORDBREAKS, the last word could be\nduplicated otherwise.\n\nCan be tested with:\n\n  git merge -X diff-algorithm=<tab>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |  2 +-\n contrib/completion/git-completion.zsh  |  2 +-\n t/t9902-completion.sh                  | 15 +++++++++++++++\n 3 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 10d225cc9c..10e69af9ed 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -347,7 +347,7 @@ __gitcomp ()\n \tlocal cur_=\"${3-$cur}\"\n \n \tcase \"$cur_\" in\n-\t--*=)\n+\t*=)\n \t\t;;\n \t--no-*)\n \t\tlocal c i=0 IFS=$' \\t\\n'\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 6c56296997..69f90913db 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -55,7 +55,7 @@ __gitcomp ()\n \tlocal cur_=\"${3-$cur}\"\n \n \tcase \"$cur_\" in\n-\t--*=)\n+\t*=)\n \t\t;;\n \t--no-*)\n \t\tlocal c IFS=$' \\t\\n'\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex a1c4f1f6d4..39760293f6 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -537,6 +537,15 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '\n \tEOF\n '\n \n+test_expect_success '__gitcomp - equal skip' '\n+\ttest_gitcomp \"--option=\" \"--option=\" <<-\\EOF &&\n+\n+\tEOF\n+\ttest_gitcomp \"option=\" \"option=\" <<-\\EOF\n+\n+\tEOF\n+'\n+\n test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '\n \t__gitcomp \"$invalid_variable_name\"\n '\n@@ -2355,6 +2364,12 @@ test_expect_success 'git clone --config= - value' '\n \tEOF\n '\n \n+test_expect_success 'options with value' '\n+\ttest_completion \"git merge -X diff-algorithm=\" <<-\\EOF\n+\n+\tEOF\n+'\n+\n test_expect_success 'sourcing the completion script clears cached commands' '\n \t__git_compute_all_commands &&\n \tverbose test -n \"$__git_all_commands\" &&\n-- \n2.30.0\n\n"},{"id":"413234","messageId":"20210101021622.798041-14-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 13/47] completion: zsh: expand --git-dir file argument","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:48Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 966b2d9277..755135a2a5 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -247,7 +247,7 @@ __git_zsh_main ()\n \t\tif (( $+opt_args[--bare] )); then\n \t\t\t__git_dir='.'\n \t\telse\n-\t\t\t__git_dir=${opt_args[--git-dir]}\n+\t\t\t__git_dir=${~opt_args[--git-dir]}\n \t\tfi\n \n \t\t(( $+opt_args[--help] )) && command='help'\n-- \n2.30.0\n\n"},{"id":"413235","messageId":"20210101021622.798041-2-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 01/47] completion: bash: fix prefix detection in branch.*","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:36Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Otherwise we are completely ignoring the --cur argument.\n\nThe issue can be tested with:\n\n  git clone --config=branch.<tab>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 463a3124da..10d225cc9c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2633,8 +2633,8 @@ __git_complete_config_variable_name ()\n \t\treturn\n \t\t;;\n \tbranch.*)\n-\t\tlocal pfx=\"${cur%.*}.\"\n-\t\tcur_=\"${cur#*.}\"\n+\t\tlocal pfx=\"${cur_%.*}.\"\n+\t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \".\")\"\n \t\t__gitcomp_nl_append $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n-- \n2.30.0\n\n"},{"id":"413236","messageId":"20210101021622.798041-5-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 04/47] completion: bash: add correct suffix in variables","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:39Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"__gitcomp automatically adds a suffix, but __gitcomp_nl and others\ndon't, we need to specify a space by default.\n\nCan be tested with:\n\n  git config branch.autoSetupMe<tab>\n\nThis fix only works for versions of bash greater than 4.0, before that\n\"local sfx\" creates an empty string, therefore the unset expansion\ndoesn't work. The same happens in zsh.\n\nTherefore we don't add the test for that for now.\n\nThe correct fix for all shells requires semantic changes in __gitcomp,\nbut that can be done later.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 64cf35ba04..926e9ceb56 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2636,7 +2636,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \".\")\"\n-\t\t__gitcomp_nl_append $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"$sfx\"\n+\t\t__gitcomp_nl_append $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"${sfx- }\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n@@ -2670,7 +2670,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__git_compute_all_commands\n-\t\t__gitcomp_nl \"$__git_all_commands\" \"$pfx\" \"$cur_\" \"$sfx\"\n+\t\t__gitcomp_nl \"$__git_all_commands\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n \t\treturn\n \t\t;;\n \tremote.*.*)\n@@ -2686,7 +2686,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n-\t\t__gitcomp_nl_append \"pushDefault\" \"$pfx\" \"$cur_\" \"$sfx\"\n+\t\t__gitcomp_nl_append \"pushDefault\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n \t\treturn\n \t\t;;\n \turl.*.*)\n-- \n2.30.0\n\n"},{"id":"413238","messageId":"20210101021622.798041-4-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 03/47] completion: bash: fix for multiple dash commands","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:38Z","receivedAt":"2021-01-01T02:17:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Otherwise commands like 'for-each-ref' are not completed.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 10e69af9ed..64cf35ba04 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -412,7 +412,7 @@ __gitcomp_builtin ()\n \tlocal incl=\"${2-}\"\n \tlocal excl=\"${3-}\"\n \n-\tlocal var=__gitcomp_builtin_\"${cmd/-/_}\"\n+\tlocal var=__gitcomp_builtin_\"${cmd//-/_}\"\n \tlocal options\n \teval \"options=\\${$var-}\"\n \n-- \n2.30.0\n\n"},{"id":"413237","messageId":"20210101021622.798041-8-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 07/47] test: completion: switch __gitcomp_nl prefix test","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:42Z","receivedAt":"2021-01-01T02:17:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"By default COMP_WORDBREAKS includes =, so it's not realistic to test for\na prefix that almost never will be there.\n\nNo functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 05469f04aa..82bf0ee2e2 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -565,9 +565,9 @@ test_expect_success '__gitcomp_nl - trailing space' '\n '\n \n test_expect_success '__gitcomp_nl - prefix' '\n-\ttest_gitcomp_nl \"--fixup=m\" \"$refs\" \"--fixup=\" \"m\" <<-EOF\n-\t--fixup=main Z\n-\t--fixup=maint Z\n+\ttest_gitcomp_nl \"branch.m\" \"$refs\" \"branch.\" \"m\" <<-EOF\n+\tbranch.main Z\n+\tbranch.maint Z\n \tEOF\n '\n \n-- \n2.30.0\n\n"},{"id":"413239","messageId":"20210101021622.798041-11-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 10/47] completion: bash: get rid of _append() functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:45Z","receivedAt":"2021-01-01T02:17:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's no need to have duplicated functionality.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 35 ++++++--------------------\n contrib/completion/git-completion.zsh  | 10 --------\n 2 files changed, 7 insertions(+), 38 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 92d0f91df9..b15d9d9d3c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -287,8 +287,7 @@ _get_comp_words_by_ref ()\n }\n fi\n \n-# Fills the COMPREPLY array with prefiltered words without any additional\n-# processing.\n+# Appends prefiltered words to COMPREPLY without any additional processing.\n # Callers must take care of providing only words that match the current word\n # to be completed and adding any prefix and/or suffix (trailing space!), if\n # necessary.\n@@ -301,19 +300,6 @@ __gitcomp_direct ()\n \tCOMPREPLY+=($1)\n }\n \n-# Similar to __gitcomp_direct, but appends to COMPREPLY instead.\n-# Callers must take care of providing only words that match the current word\n-# to be completed and adding any prefix and/or suffix (trailing space!), if\n-# necessary.\n-# 1: List of newline-separated matching completion words, complete with\n-#    prefix and suffix.\n-__gitcomp_direct_append ()\n-{\n-\tlocal IFS=$'\\n'\n-\n-\tCOMPREPLY+=($1)\n-}\n-\n __gitcompappend ()\n {\n \tlocal x i=${#COMPREPLY[@]}\n@@ -431,16 +417,8 @@ __gitcomp_builtin ()\n \t__gitcomp \"$options\"\n }\n \n-# Variation of __gitcomp_nl () that appends to the existing list of\n-# completion candidates, COMPREPLY.\n-__gitcomp_nl_append ()\n-{\n-\tlocal IFS=$'\\n'\n-\t__gitcompappend \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n-}\n-\n # Generates completion reply from newline-separated possible completion words\n-# by appending a space to all of them.\n+# by appending a space to all of them. The result is appended to COMPREPLY.\n # It accepts 1 to 4 arguments:\n # 1: List of possible completion words, separated by a single newline.\n # 2: A prefix to be added to each possible completion word (optional).\n@@ -450,7 +428,8 @@ __gitcomp_nl_append ()\n #    appended.\n __gitcomp_nl ()\n {\n-\t__gitcomp_nl_append \"$@\"\n+\tlocal IFS=$'\\n'\n+\t__gitcompappend \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n # Fills the COMPREPLY array with prefiltered paths without any additional\n@@ -837,7 +816,7 @@ __git_complete_refs ()\n \n \t# Append DWIM remote branch names if requested\n \tif [ \"$dwim\" = \"yes\" ]; then\n-\t\t__gitcomp_direct_append \"$(__git_dwim_remote_heads \"$pfx\" \"$cur_\" \"$sfx\")\"\n+\t\t__gitcomp_direct \"$(__git_dwim_remote_heads \"$pfx\" \"$cur_\" \"$sfx\")\"\n \tfi\n }\n \n@@ -2630,7 +2609,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \".\")\"\n-\t\t__gitcomp_nl_append $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"${sfx- }\"\n+\t\t__gitcomp_nl $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"${sfx- }\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n@@ -2680,7 +2659,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n-\t\t__gitcomp_nl_append \"pushDefault\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n+\t\t__gitcomp_nl \"pushDefault\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n \t\treturn\n \t\t;;\n \turl.*.*)\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex e2ea14fb33..97d2bcadd6 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -121,16 +121,6 @@ __gitcomp_file ()\n \tcompadd -f -p \"${2-}\" -- ${(f)1} && _ret=0\n }\n \n-__gitcomp_direct_append ()\n-{\n-\t__gitcomp_direct \"$@\"\n-}\n-\n-__gitcomp_nl_append ()\n-{\n-\t__gitcomp_nl \"$@\"\n-}\n-\n __gitcomp_file_direct ()\n {\n \t__gitcomp_file \"$1\" \"\"\n-- \n2.30.0\n\n"},{"id":"413240","messageId":"20210101021622.798041-9-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 08/47] test: completion: add run_func() helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:43Z","receivedAt":"2021-01-01T02:17:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Pretty straightforward: runs functions.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 58 ++++++++++++++++++-------------------------\n 1 file changed, 24 insertions(+), 34 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 82bf0ee2e2..f6c60c609a 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -75,6 +75,12 @@ run_completion ()\n \t__git_wrap__git_main && print_comp\n }\n \n+run_func ()\n+{\n+\tlocal -a COMPREPLY &&\n+\t\"$@\" && print_comp\n+}\n+\n # Test high-level completion\n # Arguments are:\n # 1: typed text so far (cur)\n@@ -452,8 +458,7 @@ test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '\n \tEOF\n \t(\n \t\tcur=should_be_ignored &&\n-\t\t__gitcomp_direct \"$(cat expected)\" &&\n-\t\tprint_comp\n+\t\trun_func __gitcomp_direct \"$(cat expected)\"\n \t) &&\n \ttest_cmp expected out\n '\n@@ -547,7 +552,7 @@ test_expect_success '__gitcomp - equal skip' '\n '\n \n test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '\n-\t__gitcomp \"$invalid_variable_name\"\n+\trun_func __gitcomp \"$invalid_variable_name\"\n '\n \n read -r -d \"\" refs <<-\\EOF\n@@ -586,7 +591,7 @@ test_expect_success '__gitcomp_nl - no suffix' '\n '\n \n test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' '\n-\t__gitcomp_nl \"$invalid_variable_name\"\n+\trun_func __gitcomp_nl \"$invalid_variable_name\"\n '\n \n test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '\n@@ -1087,8 +1092,7 @@ test_expect_success '__git_complete_refs - simple' '\n \tEOF\n \t(\n \t\tcur= &&\n-\t\t__git_complete_refs &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1100,8 +1104,7 @@ test_expect_success '__git_complete_refs - matching' '\n \tEOF\n \t(\n \t\tcur=mat &&\n-\t\t__git_complete_refs &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1114,8 +1117,7 @@ test_expect_success '__git_complete_refs - remote' '\n \tEOF\n \t(\n \t\tcur= &&\n-\t\t__git_complete_refs --remote=other &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs --remote=other\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1133,8 +1135,7 @@ test_expect_success '__git_complete_refs - track' '\n \tEOF\n \t(\n \t\tcur= &&\n-\t\t__git_complete_refs --track &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs --track\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1146,8 +1147,7 @@ test_expect_success '__git_complete_refs - current word' '\n \tEOF\n \t(\n \t\tcur=\"--option=mat\" &&\n-\t\t__git_complete_refs --cur=\"${cur#*=}\" &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs --cur=\"${cur#*=}\"\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1159,8 +1159,7 @@ test_expect_success '__git_complete_refs - prefix' '\n \tEOF\n \t(\n \t\tcur=v1.0..mat &&\n-\t\t__git_complete_refs --pfx=v1.0.. --cur=mat &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs --pfx=v1.0.. --cur=mat\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1176,8 +1175,7 @@ test_expect_success '__git_complete_refs - suffix' '\n \tEOF\n \t(\n \t\tcur= &&\n-\t\t__git_complete_refs --sfx=. &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_refs --sfx=.\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1190,8 +1188,7 @@ test_expect_success '__git_complete_fetch_refspecs - simple' '\n \tEOF\n \t(\n \t\tcur= &&\n-\t\t__git_complete_fetch_refspecs other &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_fetch_refspecs other\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1202,8 +1199,7 @@ test_expect_success '__git_complete_fetch_refspecs - matching' '\n \tEOF\n \t(\n \t\tcur=br &&\n-\t\t__git_complete_fetch_refspecs other \"\" br &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_fetch_refspecs other \"\" br\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1216,8 +1212,7 @@ test_expect_success '__git_complete_fetch_refspecs - prefix' '\n \tEOF\n \t(\n \t\tcur=\"+\" &&\n-\t\t__git_complete_fetch_refspecs other \"+\" \"\"  &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_fetch_refspecs other \"+\" \"\"\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1230,8 +1225,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified' '\n \tEOF\n \t(\n \t\tcur=refs/ &&\n-\t\t__git_complete_fetch_refspecs other \"\" refs/ &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_fetch_refspecs other \"\" refs/\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1244,8 +1238,7 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' '\n \tEOF\n \t(\n \t\tcur=+refs/ &&\n-\t\t__git_complete_fetch_refspecs other + refs/ &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_fetch_refspecs other + refs/\n \t) &&\n \ttest_cmp expected out\n '\n@@ -1776,8 +1769,7 @@ test_path_completion ()\n \t\t# unusual characters in path names.  By requesting only\n \t\t# untracked files we do not have to bother adding any\n \t\t# paths to the index in those tests.\n-\t\t__git_complete_index_file --others &&\n-\t\tprint_comp\n+\t\trun_func __git_complete_index_file --others\n \t) &&\n \ttest_cmp expected out\n }\n@@ -2281,8 +2273,7 @@ do\n \t\t(\n \t\t\twords=(git push '$flag' other ma) &&\n \t\t\tcword=${#words[@]} cur=${words[cword-1]} &&\n-\t\t\t__git_complete_remote_or_refspec &&\n-\t\t\tprint_comp\n+\t\t\trun_func __git_complete_remote_or_refspec\n \t\t) &&\n \t\ttest_cmp expected out\n \t'\n@@ -2294,8 +2285,7 @@ do\n \t\t(\n \t\t\twords=(git push other '$flag' ma) &&\n \t\t\tcword=${#words[@]} cur=${words[cword-1]} &&\n-\t\t\t__git_complete_remote_or_refspec &&\n-\t\t\tprint_comp\n+\t\t\trun_func __git_complete_remote_or_refspec\n \t\t) &&\n \t\ttest_cmp expected out\n \t'\n-- \n2.30.0\n\n"},{"id":"413242","messageId":"20210101021622.798041-18-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 17/47] completion: zsh: fix extra space on foo=","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:52Z","receivedAt":"2021-01-01T02:17:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Upstream commit e1e00089da fixed the issue for Bash, but not for Zsh.\n\nWhen we are typing configurations an = at the end signifies we still\nwant to type the value.\n\nCan be tested with:\n\n  git -c log.d<tab>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 6232d0a823..073f7d91d8 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -86,7 +86,7 @@ __gitcomp ()\n \t\t\tfi\n \t\t\tc=\"$c${4-}\"\n \t\t\tcase $c in\n-\t\t\t--*=|*.) ;;\n+\t\t\t*=|*.) ;;\n \t\t\t*) c=\"$c \" ;;\n \t\t\tesac\n \t\t\tarray+=(\"$c\")\n-- \n2.30.0\n\n"},{"id":"413246","messageId":"20210101021622.798041-24-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 23/47] completion: simplify __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:58Z","receivedAt":"2021-01-01T02:17:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's not possible for $cur_ to have anything more than --no- at this\npoint, so there's no need to add a suffix, nor check anything else.\n\nAll we are doing is checking that $cur_ matches --no, and adding a\ncompletion if so.\n\nThis way the code reflects what we are doing.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 5 ++---\n contrib/completion/git-completion.zsh  | 2 +-\n 2 files changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b356e3c86f..00a78039b8 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -332,9 +332,8 @@ __gitcomp ()\n \t\t\t\tcontinue\n \t\t\tfi\n \n-\t\t\tc=\"--no-...${4-}\"\n-\t\t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\t\tCOMPREPLY[i++]=\"${2-}$c \"\n+\t\t\tif [[ --no == \"$cur_\"* ]]; then\n+\t\t\t\tCOMPREPLY[i++]=\"--no-... \"\n \t\t\tfi\n \t\t\tbreak\n \t\tfi\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex fbd03a0180..4eef9c5199 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -62,7 +62,7 @@ __gitcomp ()\n \tfor c in ${=1}; do\n \t\tif [[ $c == \"--\" ]]; then\n \t\t\t[[ \"$cur_\" == --no-* ]] && continue\n-\t\t\tarray+=(\"--no-...${4-} \")\n+\t\t\tarray+=(\"--no-... \")\n \t\t\tbreak\n \t\tfi\n \t\tc=\"$c${4-}\"\n-- \n2.30.0\n\n"},{"id":"413241","messageId":"20210101021622.798041-22-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 21/47] completion: simplify equal suffix check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:56Z","receivedAt":"2021-01-01T02:17:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We know the prefix is already '--no-', there's no need to check for the\nfirst '--'.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n contrib/completion/git-completion.zsh  | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ff5d29bf36..0522750b9f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -335,7 +335,7 @@ __gitcomp ()\n \t\t\tc=\"$c${4-}\"\n \t\t\tif [[ $c == \"$cur_\"* ]]; then\n \t\t\t\tcase $c in\n-\t\t\t\t--*=|*.) ;;\n+\t\t\t\t*=|*.) ;;\n \t\t\t\t*) c=\"$c \" ;;\n \t\t\t\tesac\n \t\t\t\tCOMPREPLY[i++]=\"${2-}$c\"\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 090c644b71..8db7d0693d 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -67,7 +67,7 @@ __gitcomp ()\n \t\t\tfi\n \t\t\tc=\"$c${4-}\"\n \t\t\tcase $c in\n-\t\t\t--*=|*.) ;;\n+\t\t\t*=|*.) ;;\n \t\t\t*) c=\"$c \" ;;\n \t\t\tesac\n \t\t\tarray+=(\"$c\")\n-- \n2.30.0\n\n"},{"id":"413247","messageId":"20210101021622.798041-20-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 19/47] completion: zsh: always set compset","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:54Z","receivedAt":"2021-01-01T02:17:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"So we don't have to set it every time.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 7 ++-----\n 1 file changed, 2 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 7cb0f33209..d754086877 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -72,7 +72,6 @@ __gitcomp ()\n \t\t\tesac\n \t\t\tarray+=(\"$c\")\n \t\tdone\n-\t\tcompset -P '*[=:]'\n \t\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n \t\t;;\n \t*)\n@@ -91,7 +90,6 @@ __gitcomp ()\n \t\t\tesac\n \t\t\tarray+=(\"$c\")\n \t\tdone\n-\t\tcompset -P '*[=:]'\n \t\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n \t\t;;\n \tesac\n@@ -101,7 +99,6 @@ __gitcomp_direct ()\n {\n \temulate -L zsh\n \n-\tcompset -P '*[=:]'\n \tcompadd -Q -S '' -- ${(f)1} && _ret=0\n }\n \n@@ -109,7 +106,6 @@ __gitcomp_nl ()\n {\n \temulate -L zsh\n \n-\tcompset -P '*[=:]'\n \tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${(f)1} && _ret=0\n }\n \n@@ -117,7 +113,6 @@ __gitcomp_file ()\n {\n \temulate -L zsh\n \n-\tcompset -P '*[=:]'\n \tcompadd -f -p \"${2-}\" -- ${(f)1} && _ret=0\n }\n \n@@ -135,6 +130,8 @@ __git_complete_command ()\n {\n \temulate -L zsh\n \n+\tcompset -P '*[=:]'\n+\n \tlocal command=\"$1\"\n \tlocal completion_func=\"_git_${command//-/_}\"\n \tif (( $+functions[$completion_func] )); then\n-- \n2.30.0\n\n"},{"id":"413244","messageId":"20210101021622.798041-28-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 27/47] test: completion: add missing test","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:02Z","receivedAt":"2021-01-01T02:17:27Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Once the correct suffix in __git_complete_config_variable_name() is set,\nwe can add the test again.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex f6c60c609a..e1a9e9483c 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2312,6 +2312,13 @@ test_expect_success 'git config - value' '\n \tEOF\n '\n \n+test_expect_success 'git config - direct completions' '\n+\ttest_completion \"git config branch.autoSetup\" <<-\\EOF\n+\tbranch.autoSetupMerge Z\n+\tbranch.autoSetupRebase Z\n+\tEOF\n+'\n+\n test_expect_success 'git -c - section' '\n \ttest_completion \"git -c br\" <<-\\EOF\n \tbranch.Z\n-- \n2.30.0\n\n"},{"id":"413243","messageId":"20210101021622.798041-12-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 11/47] completion: bash: get rid of any non-append code","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:46Z","receivedAt":"2021-01-01T02:17:28Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 12 +++---------\n 1 file changed, 3 insertions(+), 9 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b15d9d9d3c..ec62c11fe5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -300,7 +300,7 @@ __gitcomp_direct ()\n \tCOMPREPLY+=($1)\n }\n \n-__gitcompappend ()\n+__gitcompadd ()\n {\n \tlocal x i=${#COMPREPLY[@]}\n \tfor x in $1; do\n@@ -310,12 +310,6 @@ __gitcompappend ()\n \tdone\n }\n \n-__gitcompadd ()\n-{\n-\tCOMPREPLY=()\n-\t__gitcompappend \"$@\"\n-}\n-\n # Generates completion reply, appending a space to possible completion words,\n # if necessary.\n # It accepts 1 to 4 arguments:\n@@ -429,7 +423,7 @@ __gitcomp_builtin ()\n __gitcomp_nl ()\n {\n \tlocal IFS=$'\\n'\n-\t__gitcompappend \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n }\n \n # Fills the COMPREPLY array with prefiltered paths without any additional\n@@ -442,7 +436,7 @@ __gitcomp_file_direct ()\n {\n \tlocal IFS=$'\\n'\n \n-\tCOMPREPLY=($1)\n+\tCOMPREPLY+=($1)\n \n \t# use a hack to enable file mode in bash < 4\n \tcompopt -o filenames +o nospace 2>/dev/null ||\n-- \n2.30.0\n\n"},{"id":"413245","messageId":"20210101021622.798041-26-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 25/47] completion: improve __gitcomp suffix code","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:00Z","receivedAt":"2021-01-01T02:17:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's no point in adding a suffix after a suffix.\n\nIf a suffix is provided, we add it, if not, then the default heuristic\nis used.\n\nThere's no functional change since most callers don't specify a suffix,\nand the ones that do use an =, which by default doesn't add an\nadditional suffix.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 17 ++++++++++-------\n contrib/completion/git-completion.zsh  | 18 +++++++++++-------\n 2 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 1f0728ae52..4eea322366 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -325,7 +325,7 @@ __gitcomp ()\n \t\treturn\n \tfi\n \n-\tlocal c i=0 IFS=$' \\t\\n'\n+\tlocal c i=0 IFS=$' \\t\\n' sfx\n \tfor c in $1; do\n \t\tif [[ $c == \"--\" ]]; then\n \t\t\tif [[ \"$cur_\" == --no-* ]]; then\n@@ -338,12 +338,15 @@ __gitcomp ()\n \t\t\tbreak\n \t\tfi\n \t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\tc=\"$c${4-}\"\n-\t\t\tcase $c in\n-\t\t\t*=|*.) ;;\n-\t\t\t*) c=\"$c \" ;;\n-\t\t\tesac\n-\t\t\tCOMPREPLY[i++]=\"${2-}$c\"\n+\t\t\tif [[ -z \"${4+set}\" ]]; then\n+\t\t\t\tcase $c in\n+\t\t\t\t*=|*.) sfx=\"\" ;;\n+\t\t\t\t*) sfx=\" \" ;;\n+\t\t\t\tesac\n+\t\t\telse\n+\t\t\t\tsfx=\"$4\"\n+\t\t\tfi\n+\t\t\tCOMPREPLY[i++]=\"${2-}$c$sfx\"\n \t\tfi\n \tdone\n }\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 4eef9c5199..0ef15ff643 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -57,7 +57,7 @@ __gitcomp ()\n \n \t[[ \"$cur_\" == *= ]] && return\n \n-\tlocal c IFS=$' \\t\\n'\n+\tlocal c IFS=$' \\t\\n' sfx\n \tlocal -a array\n \tfor c in ${=1}; do\n \t\tif [[ $c == \"--\" ]]; then\n@@ -65,12 +65,16 @@ __gitcomp ()\n \t\t\tarray+=(\"--no-... \")\n \t\t\tbreak\n \t\tfi\n-\t\tc=\"$c${4-}\"\n-\t\tcase $c in\n-\t\t*=|*.) ;;\n-\t\t*) c=\"$c \" ;;\n-\t\tesac\n-\t\tarray+=(\"$c\")\n+\n+\t\tif [[ -z \"${4+set}\" ]]; then\n+\t\t\tcase $c in\n+\t\t\t*=|*.) sfx=\"\" ;;\n+\t\t\t*) sfx=\" \" ;;\n+\t\t\tesac\n+\t\telse\n+\t\t\tsfx=\"$4\"\n+\t\tfi\n+\t\tarray+=(\"$c$sfx\")\n \tdone\n \tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n }\n-- \n2.30.0\n\n"},{"id":"413249","messageId":"20210101021622.798041-29-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 28/47] completion: bash: improve __gitcomp description","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:03Z","receivedAt":"2021-01-01T02:17:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It does a lot more than what is stated now.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 73c9a81405..e56f96bdd6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -310,8 +310,7 @@ __gitcompadd ()\n \tdone\n }\n \n-# Generates completion reply, appending a space to possible completion words,\n-# if necessary.\n+# Creates completion replies, reorganizing options and adding suffixes as needed.\n # It accepts 1 to 4 arguments:\n # 1: List of possible completion words.\n # 2: A prefix to be added to each possible completion word (optional).\n-- \n2.30.0\n\n"},{"id":"413250","messageId":"20210101021622.798041-13-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 12/47] completion: zsh: fix options with arguments","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:47Z","receivedAt":"2021-01-01T02:17:30Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"They support both '--git-dir=value' and '--git-dir value'. Fix the\narguments to support both.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 97d2bcadd6..966b2d9277 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -217,15 +217,15 @@ __git_zsh_main ()\n \t_arguments -C \\\n \t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n \t\t'(-p --paginate)--no-pager[do not pipe git output into a pager]' \\\n-\t\t'--git-dir=-[set the path to the repository]: :_directories' \\\n+\t\t'--git-dir=[set the path to the repository]: :_directories' \\\n \t\t'--bare[treat the repository as a bare repository]' \\\n \t\t'(- :)--version[prints the git suite version]' \\\n-\t\t'--exec-path=-[path to where your core git programs are installed]:: :_directories' \\\n+\t\t'--exec-path=[path to where your core git programs are installed]:: :_directories' \\\n \t\t'--html-path[print the path where git''s HTML documentation is installed]' \\\n \t\t'--info-path[print the path where the Info files are installed]' \\\n \t\t'--man-path[print the manpath (see `man(1)`) for the man pages]' \\\n-\t\t'--work-tree=-[set the path to the working tree]: :_directories' \\\n-\t\t'--namespace=-[set the git namespace]' \\\n+\t\t'--work-tree=[set the path to the working tree]: :_directories' \\\n+\t\t'--namespace=[set the git namespace]:' \\\n \t\t'--no-replace-objects[do not use replacement refs to replace git objects]' \\\n \t\t'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \\\n \t\t'(-): :->command' \\\n-- \n2.30.0\n\n"},{"id":"413248","messageId":"20210101021622.798041-15-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 14/47] completion: zsh: add support for general -C opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:49Z","receivedAt":"2021-01-01T02:17:32Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 755135a2a5..a9177c7dcb 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -210,7 +210,7 @@ __git_zsh_main ()\n {\n \tlocal curcontext=\"$curcontext\" state state_descr line\n \ttypeset -A opt_args\n-\tlocal -a orig_words\n+\tlocal -a orig_words __git_C_args\n \n \torig_words=( ${words[@]} )\n \n@@ -228,6 +228,7 @@ __git_zsh_main ()\n \t\t'--namespace=[set the git namespace]:' \\\n \t\t'--no-replace-objects[do not use replacement refs to replace git objects]' \\\n \t\t'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \\\n+\t\t'*-C[run as if git was started in the given path]: :_directories' \\\n \t\t'(-): :->command' \\\n \t\t'(-)*:: :->arg' && return\n \n@@ -250,6 +251,10 @@ __git_zsh_main ()\n \t\t\t__git_dir=${~opt_args[--git-dir]}\n \t\tfi\n \n+\t\tfor x in ${(s.:.)opt_args[-C]}; do\n+\t\t\t__git_C_args+=('-C' ${~x})\n+\t\tdone\n+\n \t\t(( $+opt_args[--help] )) && command='help'\n \n \t\twords=( ${orig_words[@]} )\n-- \n2.30.0\n\n"},{"id":"413251","messageId":"20210101021622.798041-17-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 16/47] completion: zsh: add support for general -c opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:51Z","receivedAt":"2021-01-01T02:17:33Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"So we can specify configurations.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 46564126e4..6232d0a823 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -232,6 +232,7 @@ __git_zsh_main ()\n \t\t'--no-replace-objects[do not use replacement refs to replace git objects]' \\\n \t\t'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \\\n \t\t'*-C[run as if git was started in the given path]: :_directories' \\\n+\t\t'*-c[pass a configuration parameter to the command]: :->config' \\\n \t\t'(-): :->command' \\\n \t\t'(-)*:: :->arg' && return\n \n@@ -245,6 +246,10 @@ __git_zsh_main ()\n \t\t\tlet _ret || break\n \t\tdone\n \t\t;;\n+\t(config)\n+\t\tcompset -P '*[=:]'\n+\t\temulate ksh -c __git_complete_config_variable_name_and_value\n+\t\t;;\n \t(arg)\n \t\tlocal command=\"${words[1]}\" __git_dir\n \n-- \n2.30.0\n\n"},{"id":"413256","messageId":"20210101021622.798041-30-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 29/47] completion: add __gitcomp_opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:04Z","receivedAt":"2021-01-01T02:17:34Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Create a new simplified version of __gitcomp for most callers, and\n__gitcomp_opts for the ones that need reorganizing all the options.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 114 ++++++++++++++-----------\n contrib/completion/git-completion.zsh  |   8 ++\n t/t9902-completion.sh                  |  58 ++++++-------\n 3 files changed, 100 insertions(+), 80 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex e56f96bdd6..faf563b783 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -310,13 +310,25 @@ __gitcompadd ()\n \tdone\n }\n \n-# Creates completion replies, reorganizing options and adding suffixes as needed.\n+# Creates completion replies.\n # It accepts 1 to 4 arguments:\n # 1: List of possible completion words.\n # 2: A prefix to be added to each possible completion word (optional).\n # 3: Generate possible completion matches for this word (optional).\n # 4: A suffix to be appended to each possible completion word (optional).\n __gitcomp ()\n+{\n+\tlocal IFS=$' \\t\\n'\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n+}\n+\n+# Creates completion replies, reorganizing options and adding suffixes as needed.\n+# It accepts 1 to 4 arguments:\n+# 1: List of possible completion words.\n+# 2: A prefix to be added to each possible completion word (optional).\n+# 3: Generate possible completion matches for this word (optional).\n+# 4: A suffix to be appended to each possible completion word (optional).\n+__gitcomp_opts ()\n {\n \tlocal cur_=\"${3-$cur}\"\n \n@@ -360,7 +372,7 @@ fi\n \n # This function is equivalent to\n #\n-#    __gitcomp \"$(git xxx --git-completion-helper) ...\"\n+#    __gitcomp_opts \"$(git xxx --git-completion-helper) ...\"\n #\n # except that the output is cached. Accept 1-3 arguments:\n # 1: the git command to execute, this is also the cache key\n@@ -395,7 +407,7 @@ __gitcomp_builtin ()\n \t\teval \"$var=\\\"$options\\\"\"\n \tfi\n \n-\t__gitcomp \"$options\"\n+\t__gitcomp_opts \"$options\"\n }\n \n # Generates completion reply from newline-separated possible completion words\n@@ -1032,7 +1044,7 @@ __git_complete_strategy ()\n \t\treturn 0\n \t\t;;\n \t-X)\n-\t\t__gitcomp \"$__git_merge_strategy_options\"\n+\t\t__gitcomp_opts \"$__git_merge_strategy_options\"\n \t\treturn 0\n \t\t;;\n \tesac\n@@ -1042,7 +1054,7 @@ __git_complete_strategy ()\n \t\treturn 0\n \t\t;;\n \t--strategy-option=*)\n-\t\t__gitcomp \"$__git_merge_strategy_options\" \"\" \"${cur##--strategy-option=}\"\n+\t\t__gitcomp_opts \"$__git_merge_strategy_options\" \"\" \"${cur##--strategy-option=}\"\n \t\treturn 0\n \t\t;;\n \tesac\n@@ -1283,7 +1295,7 @@ _git_am ()\n {\n \t__git_find_repo_path\n \tif [ -d \"$__git_repo_path\"/rebase-apply ]; then\n-\t\t__gitcomp \"$__git_am_inprogress_options\"\n+\t\t__gitcomp_opts \"$__git_am_inprogress_options\"\n \t\treturn\n \tfi\n \tcase \"$cur\" in\n@@ -1537,7 +1549,7 @@ _git_cherry_pick ()\n {\n \t__git_find_repo_path\n \tif [ -f \"$__git_repo_path\"/CHERRY_PICK_HEAD ]; then\n-\t\t__gitcomp \"$__git_cherry_pick_inprogress_options\"\n+\t\t__gitcomp_opts \"$__git_cherry_pick_inprogress_options\"\n \t\treturn\n \tfi\n \n@@ -1695,7 +1707,7 @@ _git_diff ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"$__git_diff_difftool_options\"\n+\t\t__gitcomp_opts \"$__git_diff_difftool_options\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -1989,7 +2001,7 @@ _git_log ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"\n+\t\t__gitcomp_opts \"\n \t\t\t$__git_log_common_options\n \t\t\t$__git_log_shortlog_options\n \t\t\t$__git_log_gitk_options\n@@ -2052,7 +2064,7 @@ _git_mergetool ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"--tool= --prompt --no-prompt --gui --no-gui\"\n+\t\t__gitcomp_opts \"--tool= --prompt --no-prompt --gui --no-gui\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -2200,7 +2212,7 @@ _git_range_diff ()\n {\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n+\t\t__gitcomp_opts \"\n \t\t\t--creation-factor= --no-dual-color\n \t\t\t$__git_diff_common_options\n \t\t\"\n@@ -2217,11 +2229,11 @@ _git_rebase ()\n {\n \t__git_find_repo_path\n \tif [ -f \"$__git_repo_path\"/rebase-merge/interactive ]; then\n-\t\t__gitcomp \"$__git_rebase_interactive_inprogress_options\"\n+\t\t__gitcomp_opts \"$__git_rebase_interactive_inprogress_options\"\n \t\treturn\n \telif [ -d \"$__git_repo_path\"/rebase-apply ] || \\\n \t     [ -d \"$__git_repo_path\"/rebase-merge ]; then\n-\t\t__gitcomp \"$__git_rebase_inprogress_options\"\n+\t\t__gitcomp_opts \"$__git_rebase_inprogress_options\"\n \t\treturn\n \tfi\n \t__git_complete_strategy && return\n@@ -2663,7 +2675,7 @@ __git_complete_config_variable_name ()\n \t\t\t\t\tfor (s in sections)\n \t\t\t\t\t\tprint s \".\"\n \t\t\t\t}\n-\t\t\t\t')\" \"\" \"$cur_\"\n+\t\t\t\t')\" \"\" \"$cur_\" \"\"\n \t\t;;\n \tesac\n }\n@@ -2841,7 +2853,7 @@ _git_revert ()\n {\n \t__git_find_repo_path\n \tif [ -f \"$__git_repo_path\"/REVERT_HEAD ]; then\n-\t\t__gitcomp \"$__git_revert_inprogress_options\"\n+\t\t__gitcomp_opts \"$__git_revert_inprogress_options\"\n \t\treturn\n \tfi\n \t__git_complete_strategy && return\n@@ -2873,7 +2885,7 @@ _git_shortlog ()\n \n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n+\t\t__gitcomp_opts \"\n \t\t\t$__git_log_common_options\n \t\t\t$__git_log_shortlog_options\n \t\t\t--numbered --summary --email\n@@ -2911,7 +2923,7 @@ _git_show ()\n \t\treturn\n \t\t;;\n \t--*)\n-\t\t__gitcomp \"--pretty= --format= --abbrev-commit --no-abbrev-commit\n+\t\t__gitcomp_opts \"--pretty= --format= --abbrev-commit --no-abbrev-commit\n \t\t\t--oneline --show-signature\n \t\t\t--expand-tabs --expand-tabs= --no-expand-tabs\n \t\t\t$__git_diff_common_options\n@@ -2944,10 +2956,10 @@ _git_sparse_checkout ()\n \n \tcase \"$subcommand,$cur\" in\n \tinit,--*)\n-\t\t__gitcomp \"--cone\"\n+\t\t__gitcomp_opts \"--cone\"\n \t\t;;\n \tset,--*)\n-\t\t__gitcomp \"--stdin\"\n+\t\t__gitcomp_opts \"--stdin\"\n \t\t;;\n \t*)\n \t\t;;\n@@ -2965,7 +2977,7 @@ _git_stash ()\n \tif [ -z \"$subcommand\" ]; then\n \t\tcase \"$cur\" in\n \t\t--*)\n-\t\t\t__gitcomp \"$save_opts\"\n+\t\t\t__gitcomp_opts \"$save_opts\"\n \t\t\t;;\n \t\tsa*)\n \t\t\tif [ -z \"$(__git_find_on_cmdline \"$save_opts\")\" ]; then\n@@ -2981,22 +2993,22 @@ _git_stash ()\n \telse\n \t\tcase \"$subcommand,$cur\" in\n \t\tpush,--*)\n-\t\t\t__gitcomp \"$save_opts --message\"\n+\t\t\t__gitcomp_opts \"$save_opts --message\"\n \t\t\t;;\n \t\tsave,--*)\n-\t\t\t__gitcomp \"$save_opts\"\n+\t\t\t__gitcomp_opts \"$save_opts\"\n \t\t\t;;\n \t\tapply,--*|pop,--*)\n-\t\t\t__gitcomp \"--index --quiet\"\n+\t\t\t__gitcomp_opts \"--index --quiet\"\n \t\t\t;;\n \t\tdrop,--*)\n-\t\t\t__gitcomp \"--quiet\"\n+\t\t\t__gitcomp_opts \"--quiet\"\n \t\t\t;;\n \t\tlist,--*)\n-\t\t\t__gitcomp \"--name-status --oneline --patch-with-stat\"\n+\t\t\t__gitcomp_opts \"--name-status --oneline --patch-with-stat\"\n \t\t\t;;\n \t\tshow,--*)\n-\t\t\t__gitcomp \"$__git_diff_common_options\"\n+\t\t\t__gitcomp_opts \"$__git_diff_common_options\"\n \t\t\t;;\n \t\tbranch,--*)\n \t\t\t;;\n@@ -3027,7 +3039,7 @@ _git_submodule ()\n \tif [ -z \"$subcommand\" ]; then\n \t\tcase \"$cur\" in\n \t\t--*)\n-\t\t\t__gitcomp \"--quiet\"\n+\t\t\t__gitcomp_opts \"--quiet\"\n \t\t\t;;\n \t\t*)\n \t\t\t__gitcomp \"$subcommands\"\n@@ -3038,29 +3050,29 @@ _git_submodule ()\n \n \tcase \"$subcommand,$cur\" in\n \tadd,--*)\n-\t\t__gitcomp \"--branch --force --name --reference --depth\"\n+\t\t__gitcomp_opts \"--branch --force --name --reference --depth\"\n \t\t;;\n \tstatus,--*)\n-\t\t__gitcomp \"--cached --recursive\"\n+\t\t__gitcomp_opts \"--cached --recursive\"\n \t\t;;\n \tdeinit,--*)\n-\t\t__gitcomp \"--force --all\"\n+\t\t__gitcomp_opts \"--force --all\"\n \t\t;;\n \tupdate,--*)\n-\t\t__gitcomp \"\n+\t\t__gitcomp_opts \"\n \t\t\t--init --remote --no-fetch\n \t\t\t--recommend-shallow --no-recommend-shallow\n \t\t\t--force --rebase --merge --reference --depth --recursive --jobs\n \t\t\"\n \t\t;;\n \tset-branch,--*)\n-\t\t__gitcomp \"--default --branch\"\n+\t\t__gitcomp_opts \"--default --branch\"\n \t\t;;\n \tsummary,--*)\n-\t\t__gitcomp \"--cached --files --summary-limit\"\n+\t\t__gitcomp_opts \"--cached --files --summary-limit\"\n \t\t;;\n \tforeach,--*|sync,--*)\n-\t\t__gitcomp \"--recursive\"\n+\t\t__gitcomp_opts \"--recursive\"\n \t\t;;\n \t*)\n \t\t;;\n@@ -3101,64 +3113,64 @@ _git_svn ()\n \n \t\tcase \"$subcommand,$cur\" in\n \t\tfetch,--*)\n-\t\t\t__gitcomp \"--revision= --fetch-all $fc_opts\"\n+\t\t\t__gitcomp_opts \"--revision= --fetch-all $fc_opts\"\n \t\t\t;;\n \t\tclone,--*)\n-\t\t\t__gitcomp \"--revision= $fc_opts $init_opts\"\n+\t\t\t__gitcomp_opts \"--revision= $fc_opts $init_opts\"\n \t\t\t;;\n \t\tinit,--*)\n-\t\t\t__gitcomp \"$init_opts\"\n+\t\t\t__gitcomp_opts \"$init_opts\"\n \t\t\t;;\n \t\tdcommit,--*)\n-\t\t\t__gitcomp \"\n+\t\t\t__gitcomp_opts \"\n \t\t\t\t--merge --strategy= --verbose --dry-run\n \t\t\t\t--fetch-all --no-rebase --commit-url\n \t\t\t\t--revision --interactive $cmt_opts $fc_opts\n \t\t\t\t\"\n \t\t\t;;\n \t\tset-tree,--*)\n-\t\t\t__gitcomp \"--stdin $cmt_opts $fc_opts\"\n+\t\t\t__gitcomp_opts \"--stdin $cmt_opts $fc_opts\"\n \t\t\t;;\n \t\tcreate-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\\\n \t\tshow-externals,--*|mkdirs,--*)\n-\t\t\t__gitcomp \"--revision=\"\n+\t\t\t__gitcomp_opts \"--revision=\"\n \t\t\t;;\n \t\tlog,--*)\n-\t\t\t__gitcomp \"\n+\t\t\t__gitcomp_opts \"\n \t\t\t\t--limit= --revision= --verbose --incremental\n \t\t\t\t--oneline --show-commit --non-recursive\n \t\t\t\t--authors-file= --color\n \t\t\t\t\"\n \t\t\t;;\n \t\trebase,--*)\n-\t\t\t__gitcomp \"\n+\t\t\t__gitcomp_opts \"\n \t\t\t\t--merge --verbose --strategy= --local\n \t\t\t\t--fetch-all --dry-run $fc_opts\n \t\t\t\t\"\n \t\t\t;;\n \t\tcommit-diff,--*)\n-\t\t\t__gitcomp \"--message= --file= --revision= $cmt_opts\"\n+\t\t\t__gitcomp_opts \"--message= --file= --revision= $cmt_opts\"\n \t\t\t;;\n \t\tinfo,--*)\n-\t\t\t__gitcomp \"--url\"\n+\t\t\t__gitcomp_opts \"--url\"\n \t\t\t;;\n \t\tbranch,--*)\n-\t\t\t__gitcomp \"--dry-run --message --tag\"\n+\t\t\t__gitcomp_opts \"--dry-run --message --tag\"\n \t\t\t;;\n \t\ttag,--*)\n-\t\t\t__gitcomp \"--dry-run --message\"\n+\t\t\t__gitcomp_opts \"--dry-run --message\"\n \t\t\t;;\n \t\tblame,--*)\n-\t\t\t__gitcomp \"--git-format\"\n+\t\t\t__gitcomp_opts \"--git-format\"\n \t\t\t;;\n \t\tmigrate,--*)\n-\t\t\t__gitcomp \"\n+\t\t\t__gitcomp_opts \"\n \t\t\t\t--config-dir= --ignore-paths= --minimize\n \t\t\t\t--no-auth-cache --username=\n \t\t\t\t\"\n \t\t\t;;\n \t\treset,--*)\n-\t\t\t__gitcomp \"--revision= --parent\"\n+\t\t\t__gitcomp_opts \"--revision= --parent\"\n \t\t\t;;\n \t\t*)\n \t\t\t;;\n@@ -3373,7 +3385,7 @@ __git_main ()\n \t\t\t;;\n \t\tesac\n \t\tcase \"$cur\" in\n-\t\t--*)   __gitcomp \"\n+\t\t--*)   __gitcomp_opts \"\n \t\t\t--paginate\n \t\t\t--no-pager\n \t\t\t--git-dir=\n@@ -3424,7 +3436,7 @@ __gitk_main ()\n \tfi\n \tcase \"$cur\" in\n \t--*)\n-\t\t__gitcomp \"\n+\t\t__gitcomp_opts \"\n \t\t\t$__git_log_common_options\n \t\t\t$__git_log_gitk_options\n \t\t\t$merge\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 0ef15ff643..d5ec8a1417 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -53,6 +53,14 @@ __gitcomp ()\n {\n \temulate -L zsh\n \n+\tlocal IFS=$' \\t\\n'\n+\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n+}\n+\n+__gitcomp_opts ()\n+{\n+\temulate -L zsh\n+\n \tlocal cur_=\"${3-$cur}\"\n \n \t[[ \"$cur_\" == *= ]] && return\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex e1a9e9483c..50b7b04021 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -98,17 +98,17 @@ test_completion ()\n \ttest_cmp expected out_sorted\n }\n \n-# Test __gitcomp.\n+# Test __gitcomp_opts.\n # The first argument is the typed text so far (cur); the rest are\n-# passed to __gitcomp.  Expected output comes is read from the\n+# passed to __gitcomp_opts.  Expected output comes is read from the\n # standard input, like test_completion().\n-test_gitcomp ()\n+test_gitcomp_opts ()\n {\n \tlocal -a COMPREPLY &&\n \tsed -e 's/Z$//' >expected &&\n \tlocal cur=\"$1\" &&\n \tshift &&\n-\t__gitcomp \"$@\" &&\n+\t__gitcomp_opts \"$@\" &&\n \tprint_comp &&\n \ttest_cmp expected out\n }\n@@ -463,8 +463,8 @@ test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '\n \ttest_cmp expected out\n '\n \n-test_expect_success '__gitcomp - trailing space - options' '\n-\ttest_gitcomp \"--re\" \"--dry-run --reuse-message= --reedit-message=\n+test_expect_success '__gitcomp_opts - trailing space - options' '\n+\ttest_gitcomp_opts \"--re\" \"--dry-run --reuse-message= --reedit-message=\n \t\t--reset-author\" <<-EOF\n \t--reuse-message=Z\n \t--reedit-message=Z\n@@ -472,8 +472,8 @@ test_expect_success '__gitcomp - trailing space - options' '\n \tEOF\n '\n \n-test_expect_success '__gitcomp - trailing space - config keys' '\n-\ttest_gitcomp \"br\" \"branch. branch.autosetupmerge\n+test_expect_success '__gitcomp_opts - trailing space - config keys' '\n+\ttest_gitcomp_opts \"br\" \"branch. branch.autosetupmerge\n \t\tbranch.autosetuprebase browser.\" <<-\\EOF\n \tbranch.Z\n \tbranch.autosetupmerge Z\n@@ -482,32 +482,32 @@ test_expect_success '__gitcomp - trailing space - config keys' '\n \tEOF\n '\n \n-test_expect_success '__gitcomp - option parameter' '\n-\ttest_gitcomp \"--strategy=re\" \"octopus ours recursive resolve subtree\" \\\n+test_expect_success '__gitcomp_opts - option parameter' '\n+\ttest_gitcomp_opts \"--strategy=re\" \"octopus ours recursive resolve subtree\" \\\n \t\t\"\" \"re\" <<-\\EOF\n \trecursive Z\n \tresolve Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - prefix' '\n-\ttest_gitcomp \"branch.maint.me\" \"remote merge mergeoptions rebase\" \\\n+test_expect_success '__gitcomp_opts - prefix' '\n+\ttest_gitcomp_opts \"branch.maint.me\" \"remote merge mergeoptions rebase\" \\\n \t\t\"branch.maint.\" \"me\" <<-\\EOF\n \tbranch.maint.merge Z\n \tbranch.maint.mergeoptions Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - suffix' '\n-\ttest_gitcomp \"branch.ma\" \"master maint next seen\" \"branch.\" \\\n+test_expect_success '__gitcomp_opts - suffix' '\n+\ttest_gitcomp_opts \"branch.ma\" \"master maint next seen\" \"branch.\" \\\n \t\t\"ma\" \".\" <<-\\EOF\n \tbranch.master.Z\n \tbranch.maint.Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - ignore optional negative options' '\n-\ttest_gitcomp \"--\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n+test_expect_success '__gitcomp_opts - ignore optional negative options' '\n+\ttest_gitcomp_opts \"--\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n \t--abc Z\n \t--def Z\n \t--no-one Z\n@@ -515,44 +515,44 @@ test_expect_success '__gitcomp - ignore optional negative options' '\n \tEOF\n '\n \n-test_expect_success '__gitcomp - ignore/narrow optional negative options' '\n-\ttest_gitcomp \"--a\" \"--abc --abcdef --no-one -- --no-two\" <<-\\EOF\n+test_expect_success '__gitcomp_opts - ignore/narrow optional negative options' '\n+\ttest_gitcomp_opts \"--a\" \"--abc --abcdef --no-one -- --no-two\" <<-\\EOF\n \t--abc Z\n \t--abcdef Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - ignore/narrow optional negative options' '\n-\ttest_gitcomp \"--n\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n+test_expect_success '__gitcomp_opts - ignore/narrow optional negative options' '\n+\ttest_gitcomp_opts \"--n\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n \t--no-one Z\n \t--no-... Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - expand all negative options' '\n-\ttest_gitcomp \"--no-\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n+test_expect_success '__gitcomp_opts - expand all negative options' '\n+\ttest_gitcomp_opts \"--no-\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n \t--no-one Z\n \t--no-two Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - expand/narrow all negative options' '\n-\ttest_gitcomp \"--no-o\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n+test_expect_success '__gitcomp_opts - expand/narrow all negative options' '\n+\ttest_gitcomp_opts \"--no-o\" \"--abc --def --no-one -- --no-two\" <<-\\EOF\n \t--no-one Z\n \tEOF\n '\n \n-test_expect_success '__gitcomp - equal skip' '\n-\ttest_gitcomp \"--option=\" \"--option=\" <<-\\EOF &&\n+test_expect_success '__gitcomp_opts - equal skip' '\n+\ttest_gitcomp_opts \"--option=\" \"--option=\" <<-\\EOF &&\n \n \tEOF\n-\ttest_gitcomp \"option=\" \"option=\" <<-\\EOF\n+\ttest_gitcomp_opts \"option=\" \"option=\" <<-\\EOF\n \n \tEOF\n '\n \n-test_expect_success '__gitcomp - doesnt fail because of invalid variable name' '\n-\trun_func __gitcomp \"$invalid_variable_name\"\n+test_expect_success '__gitcomp_opts - doesnt fail because of invalid variable name' '\n+\trun_func __gitcomp_opts \"$invalid_variable_name\"\n '\n \n read -r -d \"\" refs <<-\\EOF\n-- \n2.30.0\n\n"},{"id":"413252","messageId":"20210101021622.798041-31-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 30/47] completion: bash: cleanup __gitcomp* invocations","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:05Z","receivedAt":"2021-01-01T02:17:35Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Some __gitcomp calls should be __gitcomp_nl, and vice versa.\n\nNo functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 22 +++++++++-------------\n 1 file changed, 9 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex faf563b783..9bcb484656 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1355,7 +1355,7 @@ _git_archive ()\n {\n \tcase \"$cur\" in\n \t--format=*)\n-\t\t__gitcomp \"$(git archive --list)\" \"\" \"${cur##--format=}\"\n+\t\t__gitcomp_nl \"$(git archive --list)\" \"\" \"${cur##--format=}\"\n \t\treturn\n \t\t;;\n \t--remote=*)\n@@ -1766,9 +1766,7 @@ _git_format_patch ()\n {\n \tcase \"$cur\" in\n \t--thread=*)\n-\t\t__gitcomp \"\n-\t\t\tdeep shallow\n-\t\t\t\" \"\" \"${cur##--thread=}\"\n+\t\t__gitcomp \"deep shallow\" \"\" \"${cur##--thread=}\"\n \t\treturn\n \t\t;;\n \t--base=*|--interdiff=*|--range-diff=*)\n@@ -2274,7 +2272,7 @@ _git_send_email ()\n {\n \tcase \"$prev\" in\n \t--to|--cc|--bcc|--from)\n-\t\t__gitcomp \"$(__git send-email --dump-aliases)\"\n+\t\t__gitcomp_nl \"$(__git send-email --dump-aliases)\"\n \t\treturn\n \t\t;;\n \tesac\n@@ -2298,9 +2296,7 @@ _git_send_email ()\n \t\treturn\n \t\t;;\n \t--thread=*)\n-\t\t__gitcomp \"\n-\t\t\tdeep shallow\n-\t\t\t\" \"\" \"${cur##--thread=}\"\n+\t\t__gitcomp \"deep shallow\" \"\" \"${cur##--thread=}\"\n \t\treturn\n \t\t;;\n \t--to=*|--cc=*|--bcc=*|--from=*)\n@@ -2602,7 +2598,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \".\")\"\n-\t\t__gitcomp_nl $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"$sfx\"\n+\t\t__gitcomp \"autoSetupMerge autoSetupRebase\" \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n@@ -2652,7 +2648,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n-\t\t__gitcomp_nl \"pushDefault\" \"$pfx\" \"$cur_\" \"$sfx\"\n+\t\t__gitcomp \"pushDefault\" \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n \t\t;;\n \turl.*.*)\n@@ -2667,7 +2663,7 @@ __git_complete_config_variable_name ()\n \t\t;;\n \t*)\n \t\t__git_compute_config_vars\n-\t\t__gitcomp \"$(echo \"$__git_config_vars\" |\n+\t\t__gitcomp_nl \"$(echo \"$__git_config_vars\" |\n \t\t\t\tawk -F . '{\n \t\t\t\t\tsections[$1] = 1\n \t\t\t\t}\n@@ -2769,7 +2765,7 @@ _git_remote ()\n \t\t__gitcomp_builtin remote_update\n \t\t;;\n \tupdate,*)\n-\t\t__gitcomp \"$(__git_remotes) $(__git_get_config_variables \"remotes\")\"\n+\t\t__gitcomp_nl \"$(__git_remotes) $(__git_get_config_variables \"remotes\")\"\n \t\t;;\n \tset-url,--*)\n \t\t__gitcomp_builtin remote_set-url\n@@ -3407,7 +3403,7 @@ __git_main ()\n \t\t\tthen\n \t\t\t\t__gitcomp \"$GIT_TESTING_PORCELAIN_COMMAND_LIST\"\n \t\t\telse\n-\t\t\t\t__gitcomp \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n+\t\t\t\t__gitcomp_nl \"$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)\"\n \t\t\tfi\n \t\t\t;;\n \t\tesac\n-- \n2.30.0\n\n"},{"id":"413253","messageId":"20210101021622.798041-10-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 09/47] completion: bash: remove non-append functionality","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:44Z","receivedAt":"2021-01-01T02:17:37Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's no point in setting COMPREPLY only to override it later, and in\nfact; we don't do that.\n\nTherefore there's no functional difference between __gitcomp_direct()\nand __gitcomp_direct_append(), since __gitcomp_direct() *always*\noperates on empty COMPREPLY.\n\nThe same goes for __gitcomp_nl().\n\nThis patch makes the functionality of append and non-append functions\nthe same.\n\nThere should be no functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 9ea31f7d4d..92d0f91df9 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -298,7 +298,7 @@ __gitcomp_direct ()\n {\n \tlocal IFS=$'\\n'\n \n-\tCOMPREPLY=($1)\n+\tCOMPREPLY+=($1)\n }\n \n # Similar to __gitcomp_direct, but appends to COMPREPLY instead.\n@@ -450,7 +450,6 @@ __gitcomp_nl_append ()\n #    appended.\n __gitcomp_nl ()\n {\n-\tCOMPREPLY=()\n \t__gitcomp_nl_append \"$@\"\n }\n \n-- \n2.30.0\n\n"},{"id":"413254","messageId":"20210101021622.798041-34-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 33/47] completion: zsh: shuffle __gitcomp* functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:08Z","receivedAt":"2021-01-01T02:17:38Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 6afcf1810b..3665167b3f 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -87,11 +87,6 @@ __gitcomp_opts ()\n \tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n }\n \n-__gitcomp_direct ()\n-{\n-\t__gitcomp_nl \"$1\" \"\" \"\" \"\"\n-}\n-\n __gitcomp_nl ()\n {\n \temulate -L zsh\n@@ -106,6 +101,11 @@ __gitcomp_file ()\n \tcompadd -f -p \"${2-}\" -- ${(f)1} && _ret=0\n }\n \n+__gitcomp_direct ()\n+{\n+\t__gitcomp_nl \"$1\" \"\" \"\" \"\"\n+}\n+\n __gitcomp_file_direct ()\n {\n \t__gitcomp_file \"$1\" \"\"\n-- \n2.30.0\n\n"},{"id":"413255","messageId":"20210101021622.798041-36-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 35/47] completion: zsh: add elements individually in __gitcomp_opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:10Z","receivedAt":"2021-01-01T02:17:39Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's useful to specify specific suffixes for specific words.\n\nThis will be useful later on.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 2faf435087..82a4d6f470 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -66,11 +66,10 @@ __gitcomp_opts ()\n \t[[ \"$cur_\" == *= ]] && return\n \n \tlocal c IFS=$' \\t\\n' sfx\n-\tlocal -a array\n \tfor c in ${=1}; do\n \t\tif [[ $c == \"--\" ]]; then\n \t\t\t[[ \"$cur_\" == --no-* ]] && continue\n-\t\t\tarray+=(\"--no-... \")\n+\t\t\tcompadd -S \" \" -- \"--no-...\" && _ret=0\n \t\t\tbreak\n \t\tfi\n \n@@ -82,9 +81,8 @@ __gitcomp_opts ()\n \t\telse\n \t\t\tsfx=\"$4\"\n \t\tfi\n-\t\tarray+=(\"$c$sfx\")\n+\t\tcompadd -S \"$sfx\" -p \"${2-}\" -- \"$c\" && _ret=0\n \tdone\n-\tcompadd -S '' -p \"${2-}\" -a -- array && _ret=0\n }\n \n __gitcomp_nl ()\n-- \n2.30.0\n\n"},{"id":"413257","messageId":"20210101021622.798041-37-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 36/47] completion: zsh: add __gitcompadd helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:11Z","receivedAt":"2021-01-01T02:17:40Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"So we don't have to do the same over and over.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 82a4d6f470..4e9699f542 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -49,12 +49,16 @@ COMP_WORDBREAKS=':'\n GIT_SOURCING_ZSH_COMPLETION=y . \"$script\"\n functions[complete]=\"$old_complete\"\n \n+__gitcompadd ()\n+{\n+\tcompadd -p \"${2-}\" -S \"${3- }\" -- ${=1} && _ret=0\n+}\n+\n __gitcomp ()\n {\n \temulate -L zsh\n \n-\tlocal IFS=$' \\t\\n'\n-\tcompadd -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n+\tIFS=$' \\t\\n' __gitcompadd \"$1\" \"${2-}\" \"${4- }\"\n }\n \n __gitcomp_opts ()\n@@ -69,7 +73,7 @@ __gitcomp_opts ()\n \tfor c in ${=1}; do\n \t\tif [[ $c == \"--\" ]]; then\n \t\t\t[[ \"$cur_\" == --no-* ]] && continue\n-\t\t\tcompadd -S \" \" -- \"--no-...\" && _ret=0\n+\t\t\t__gitcompadd \"--no-...\"\n \t\t\tbreak\n \t\tfi\n \n@@ -81,7 +85,7 @@ __gitcomp_opts ()\n \t\telse\n \t\t\tsfx=\"$4\"\n \t\tfi\n-\t\tcompadd -S \"$sfx\" -p \"${2-}\" -- \"$c\" && _ret=0\n+\t\t__gitcompadd \"$c\" \"${2-}\" \"$sfx\"\n \tdone\n }\n \n-- \n2.30.0\n\n"},{"id":"413258","messageId":"20210101021622.798041-32-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 31/47] completion: bash: shuffle __gitcomp functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:06Z","receivedAt":"2021-01-01T02:17:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"They are the ones that actually do the completion, put them at the top.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 270 +++++++++++++------------\n 1 file changed, 139 insertions(+), 131 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 9bcb484656..3fa597ce71 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -45,6 +45,145 @@\n #     When set to \"1\" suggest all options, including options which are\n #     typically hidden (e.g. '--allow-empty' for 'git commit').\n \n+# The following functions are meant to modify COMPREPLY, which should not be\n+# modified directly.  The purpose is to localize the modifications so it's\n+# easier to emulate it in Zsh. Every time a new __gitcomp* function is added,\n+# the corresponding function should be added to Zsh.\n+\n+__gitcompadd ()\n+{\n+\tlocal x i=${#COMPREPLY[@]}\n+\tfor x in $1; do\n+\t\tif [[ \"$x\" == \"$3\"* ]]; then\n+\t\t\tCOMPREPLY[i++]=\"$2$x$4\"\n+\t\tfi\n+\tdone\n+}\n+\n+# Creates completion replies.\n+# It accepts 1 to 4 arguments:\n+# 1: List of possible completion words.\n+# 2: A prefix to be added to each possible completion word (optional).\n+# 3: Generate possible completion matches for this word (optional).\n+# 4: A suffix to be appended to each possible completion word (optional).\n+__gitcomp ()\n+{\n+\tlocal IFS=$' \\t\\n'\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n+}\n+\n+# Generates completion reply from newline-separated possible completion words\n+# by appending a space to all of them. The result is appended to COMPREPLY.\n+# It accepts 1 to 4 arguments:\n+# 1: List of possible completion words, separated by a single newline.\n+# 2: A prefix to be added to each possible completion word (optional).\n+# 3: Generate possible completion matches for this word (optional).\n+# 4: A suffix to be appended to each possible completion word instead of\n+#    the default space (optional).  If specified but empty, nothing is\n+#    appended.\n+__gitcomp_nl ()\n+{\n+\tlocal IFS=$'\\n'\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n+}\n+\n+# Appends prefiltered words to COMPREPLY without any additional processing.\n+# Callers must take care of providing only words that match the current word\n+# to be completed and adding any prefix and/or suffix (trailing space!), if\n+# necessary.\n+# 1: List of newline-separated matching completion words, complete with\n+#    prefix and suffix.\n+__gitcomp_direct ()\n+{\n+\tlocal IFS=$'\\n'\n+\n+\tCOMPREPLY+=($1)\n+}\n+\n+# Generates completion reply with compgen from newline-separated possible\n+# completion filenames.\n+# It accepts 1 to 3 arguments:\n+# 1: List of possible completion filenames, separated by a single newline.\n+# 2: A directory prefix to be added to each possible completion filename\n+#    (optional).\n+# 3: Generate possible completion matches for this word (optional).\n+__gitcomp_file ()\n+{\n+\tlocal IFS=$'\\n'\n+\n+\t# XXX does not work when the directory prefix contains a tilde,\n+\t# since tilde expansion is not applied.\n+\t# This means that COMPREPLY will be empty and Bash default\n+\t# completion will be used.\n+\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"\"\n+\n+\t# use a hack to enable file mode in bash < 4\n+\tcompopt -o filenames +o nospace 2>/dev/null ||\n+\tcompgen -f /non-existing-dir/ >/dev/null ||\n+\ttrue\n+}\n+\n+# Fills the COMPREPLY array with prefiltered paths without any additional\n+# processing.\n+# Callers must take care of providing only paths that match the current path\n+# to be completed and adding any prefix path components, if necessary.\n+# 1: List of newline-separated matching paths, complete with all prefix\n+#    path components.\n+__gitcomp_file_direct ()\n+{\n+\tlocal IFS=$'\\n'\n+\n+\tCOMPREPLY+=($1)\n+\n+\t# use a hack to enable file mode in bash < 4\n+\tcompopt -o filenames +o nospace 2>/dev/null ||\n+\tcompgen -f /non-existing-dir/ >/dev/null ||\n+\ttrue\n+}\n+\n+# Creates completion replies, reorganizing options and adding suffixes as needed.\n+# It accepts 1 to 4 arguments:\n+# 1: List of possible completion words.\n+# 2: A prefix to be added to each possible completion word (optional).\n+# 3: Generate possible completion matches for this word (optional).\n+# 4: A suffix to be appended to each possible completion word (optional).\n+__gitcomp_opts ()\n+{\n+\tlocal cur_=\"${3-$cur}\"\n+\n+\tif [[ \"$cur_\" == *= ]]; then\n+\t\treturn\n+\tfi\n+\n+\tlocal c i=0 IFS=$' \\t\\n' sfx\n+\tfor c in $1; do\n+\t\tif [[ $c == \"--\" ]]; then\n+\t\t\tif [[ \"$cur_\" == --no-* ]]; then\n+\t\t\t\tcontinue\n+\t\t\tfi\n+\n+\t\t\tif [[ --no == \"$cur_\"* ]]; then\n+\t\t\t\tCOMPREPLY[i++]=\"--no-... \"\n+\t\t\tfi\n+\t\t\tbreak\n+\t\tfi\n+\t\tif [[ $c == \"$cur_\"* ]]; then\n+\t\t\tif [[ -z \"${4+set}\" ]]; then\n+\t\t\t\tcase $c in\n+\t\t\t\t*=|*.) sfx=\"\" ;;\n+\t\t\t\t*) sfx=\" \" ;;\n+\t\t\t\tesac\n+\t\t\telse\n+\t\t\t\tsfx=\"$4\"\n+\t\t\tfi\n+\t\t\tCOMPREPLY[i++]=\"${2-}$c$sfx\"\n+\t\tfi\n+\tdone\n+}\n+\n+# __gitcomp functions end here\n+# ==============================================================================\n+\n # Discovers the path to the git repository taking any '--git-dir=<path>' and\n # '-C <path>' options into account and stores it in the $__git_repo_path\n # variable.\n@@ -287,81 +426,6 @@ _get_comp_words_by_ref ()\n }\n fi\n \n-# Appends prefiltered words to COMPREPLY without any additional processing.\n-# Callers must take care of providing only words that match the current word\n-# to be completed and adding any prefix and/or suffix (trailing space!), if\n-# necessary.\n-# 1: List of newline-separated matching completion words, complete with\n-#    prefix and suffix.\n-__gitcomp_direct ()\n-{\n-\tlocal IFS=$'\\n'\n-\n-\tCOMPREPLY+=($1)\n-}\n-\n-__gitcompadd ()\n-{\n-\tlocal x i=${#COMPREPLY[@]}\n-\tfor x in $1; do\n-\t\tif [[ \"$x\" == \"$3\"* ]]; then\n-\t\t\tCOMPREPLY[i++]=\"$2$x$4\"\n-\t\tfi\n-\tdone\n-}\n-\n-# Creates completion replies.\n-# It accepts 1 to 4 arguments:\n-# 1: List of possible completion words.\n-# 2: A prefix to be added to each possible completion word (optional).\n-# 3: Generate possible completion matches for this word (optional).\n-# 4: A suffix to be appended to each possible completion word (optional).\n-__gitcomp ()\n-{\n-\tlocal IFS=$' \\t\\n'\n-\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n-}\n-\n-# Creates completion replies, reorganizing options and adding suffixes as needed.\n-# It accepts 1 to 4 arguments:\n-# 1: List of possible completion words.\n-# 2: A prefix to be added to each possible completion word (optional).\n-# 3: Generate possible completion matches for this word (optional).\n-# 4: A suffix to be appended to each possible completion word (optional).\n-__gitcomp_opts ()\n-{\n-\tlocal cur_=\"${3-$cur}\"\n-\n-\tif [[ \"$cur_\" == *= ]]; then\n-\t\treturn\n-\tfi\n-\n-\tlocal c i=0 IFS=$' \\t\\n' sfx\n-\tfor c in $1; do\n-\t\tif [[ $c == \"--\" ]]; then\n-\t\t\tif [[ \"$cur_\" == --no-* ]]; then\n-\t\t\t\tcontinue\n-\t\t\tfi\n-\n-\t\t\tif [[ --no == \"$cur_\"* ]]; then\n-\t\t\t\tCOMPREPLY[i++]=\"--no-... \"\n-\t\t\tfi\n-\t\t\tbreak\n-\t\tfi\n-\t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\tif [[ -z \"${4+set}\" ]]; then\n-\t\t\t\tcase $c in\n-\t\t\t\t*=|*.) sfx=\"\" ;;\n-\t\t\t\t*) sfx=\" \" ;;\n-\t\t\t\tesac\n-\t\t\telse\n-\t\t\t\tsfx=\"$4\"\n-\t\t\tfi\n-\t\t\tCOMPREPLY[i++]=\"${2-}$c$sfx\"\n-\t\tfi\n-\tdone\n-}\n-\n # Clear the variables caching builtins' options when (re-)sourcing\n # the completion script.\n if [[ -n ${ZSH_VERSION-} ]]; then\n@@ -410,62 +474,6 @@ __gitcomp_builtin ()\n \t__gitcomp_opts \"$options\"\n }\n \n-# Generates completion reply from newline-separated possible completion words\n-# by appending a space to all of them. The result is appended to COMPREPLY.\n-# It accepts 1 to 4 arguments:\n-# 1: List of possible completion words, separated by a single newline.\n-# 2: A prefix to be added to each possible completion word (optional).\n-# 3: Generate possible completion matches for this word (optional).\n-# 4: A suffix to be appended to each possible completion word instead of\n-#    the default space (optional).  If specified but empty, nothing is\n-#    appended.\n-__gitcomp_nl ()\n-{\n-\tlocal IFS=$'\\n'\n-\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"${4- }\"\n-}\n-\n-# Fills the COMPREPLY array with prefiltered paths without any additional\n-# processing.\n-# Callers must take care of providing only paths that match the current path\n-# to be completed and adding any prefix path components, if necessary.\n-# 1: List of newline-separated matching paths, complete with all prefix\n-#    path components.\n-__gitcomp_file_direct ()\n-{\n-\tlocal IFS=$'\\n'\n-\n-\tCOMPREPLY+=($1)\n-\n-\t# use a hack to enable file mode in bash < 4\n-\tcompopt -o filenames +o nospace 2>/dev/null ||\n-\tcompgen -f /non-existing-dir/ >/dev/null ||\n-\ttrue\n-}\n-\n-# Generates completion reply with compgen from newline-separated possible\n-# completion filenames.\n-# It accepts 1 to 3 arguments:\n-# 1: List of possible completion filenames, separated by a single newline.\n-# 2: A directory prefix to be added to each possible completion filename\n-#    (optional).\n-# 3: Generate possible completion matches for this word (optional).\n-__gitcomp_file ()\n-{\n-\tlocal IFS=$'\\n'\n-\n-\t# XXX does not work when the directory prefix contains a tilde,\n-\t# since tilde expansion is not applied.\n-\t# This means that COMPREPLY will be empty and Bash default\n-\t# completion will be used.\n-\t__gitcompadd \"$1\" \"${2-}\" \"${3-$cur}\" \"\"\n-\n-\t# use a hack to enable file mode in bash < 4\n-\tcompopt -o filenames +o nospace 2>/dev/null ||\n-\tcompgen -f /non-existing-dir/ >/dev/null ||\n-\ttrue\n-}\n-\n # Execute 'git ls-files', unless the --committable option is specified, in\n # which case it runs 'git diff-index' to find out the files that can be\n # committed.  It return paths relative to the directory specified in the first\n-- \n2.30.0\n\n"},{"id":"413259","messageId":"20210101021622.798041-39-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 38/47] completion: bash: simplify _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:13Z","receivedAt":"2021-01-01T02:17:42Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We don't need the whole functionality of _get_comp_words_by_ref(), we\nknow exactly what we need from that function, so only do that.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 30 ++++++--------------------\n t/t9902-completion.sh                  | 21 ++++--------------\n 2 files changed, 10 insertions(+), 41 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3fa597ce71..0510010ff6 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -399,30 +399,12 @@ __git_reassemble_comp_words_by_ref()\n if ! type _get_comp_words_by_ref >/dev/null 2>&1; then\n _get_comp_words_by_ref ()\n {\n-\tlocal exclude cur_ words_ cword_\n-\tif [ \"$1\" = \"-n\" ]; then\n-\t\texclude=$2\n-\t\tshift 2\n-\tfi\n-\t__git_reassemble_comp_words_by_ref \"$exclude\"\n-\tcur_=${words_[cword_]}\n-\twhile [ $# -gt 0 ]; do\n-\t\tcase \"$1\" in\n-\t\tcur)\n-\t\t\tcur=$cur_\n-\t\t\t;;\n-\t\tprev)\n-\t\t\tprev=${words_[$cword_-1]}\n-\t\t\t;;\n-\t\twords)\n-\t\t\twords=(\"${words_[@]}\")\n-\t\t\t;;\n-\t\tcword)\n-\t\t\tcword=$cword_\n-\t\t\t;;\n-\t\tesac\n-\t\tshift\n-\tdone\n+\tlocal words_ cword_\n+\t__git_reassemble_comp_words_by_ref \"=:\"\n+\tcword=$cword_\n+\tcur=${words_[cword]}\n+\tprev=${words_[cword-1]}\n+\twords=(\"${words_[@]}\")\n }\n fi\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 50b7b04021..363d8817af 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -40,23 +40,10 @@ GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n # So let's override it with a minimal version for testing purposes.\n _get_comp_words_by_ref ()\n {\n-\twhile [ $# -gt 0 ]; do\n-\t\tcase \"$1\" in\n-\t\tcur)\n-\t\t\tcur=${_words[_cword]}\n-\t\t\t;;\n-\t\tprev)\n-\t\t\tprev=${_words[_cword-1]}\n-\t\t\t;;\n-\t\twords)\n-\t\t\twords=(\"${_words[@]}\")\n-\t\t\t;;\n-\t\tcword)\n-\t\t\tcword=$_cword\n-\t\t\t;;\n-\t\tesac\n-\t\tshift\n-\tdone\n+\tcword=$_cword\n+\tcur=${_words[cword]}\n+\tprev=${_words[cword-1]}\n+\twords=(\"${_words[@]}\")\n }\n \n print_comp ()\n-- \n2.30.0\n\n"},{"id":"413260","messageId":"20210101021622.798041-38-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 37/47] completion: zsh: add correct removable suffix","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:12Z","receivedAt":"2021-01-01T02:17:42Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Zsh has a nice feature that allows a suffix to be automatically removed\nif followed by a space.\n\nFor example:\n\n  git log --prety=\n\nIf a space is typed, the suffix '=' is removed.\n\nBut we have to set the correct prefix first.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 4e9699f542..43b7c1b210 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -51,7 +51,7 @@ functions[complete]=\"$old_complete\"\n \n __gitcompadd ()\n {\n-\tcompadd -p \"${2-}\" -S \"${3- }\" -- ${=1} && _ret=0\n+\tcompadd -p \"${2-}\" -S \"${3- }\" -q -- ${=1} && _ret=0\n }\n \n __gitcomp ()\n@@ -79,7 +79,8 @@ __gitcomp_opts ()\n \n \t\tif [[ -z \"${4+set}\" ]]; then\n \t\t\tcase $c in\n-\t\t\t*=|*.) sfx=\"\" ;;\n+\t\t\t*=) c=\"${c%=}\"; sfx=\"=\" ;;\n+\t\t\t*.) sfx=\"\" ;;\n \t\t\t*) sfx=\" \" ;;\n \t\t\tesac\n \t\telse\n-- \n2.30.0\n\n"},{"id":"413261","messageId":"20210101021622.798041-40-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 39/47] completion: bash: refactor _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:14Z","receivedAt":"2021-01-01T02:17:44Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We don't need a separate function to do what we already know we want to\ndo.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 93 +++++++++++---------------\n 1 file changed, 39 insertions(+), 54 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0510010ff6..040391f881 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -325,21 +325,11 @@ __git_dequote ()\n #\n #   RELEASE: 2.x\n \n-# This function can be used to access a tokenized list of words\n-# on the command line:\n-#\n-#\t__git_reassemble_comp_words_by_ref '=:'\n-#\tif test \"${words_[cword_-1]}\" = -w\n-#\tthen\n-#\t\t...\n-#\tfi\n-#\n-# The argument should be a collection of characters from the list of\n-# word completion separators (COMP_WORDBREAKS) to treat as ordinary\n-# characters.\n+# This function reorganizes the words on the command line to be processed by\n+# the rest of the script.\n #\n # This is roughly equivalent to going back in time and setting\n-# COMP_WORDBREAKS to exclude those characters.  The intent is to\n+# COMP_WORDBREAKS to exclude '=' and ':'.  The intent is to\n # make option types like --date=<type> and <rev>:<path> easy to\n # recognize by treating each shell word as a single token.\n #\n@@ -347,60 +337,55 @@ __git_dequote ()\n # shared with other completion scripts.  By the time the completion\n # function gets called, COMP_WORDS has already been populated so local\n # changes to COMP_WORDBREAKS have no effect.\n-#\n-# Output: words_, cword_, cur_.\n \n-__git_reassemble_comp_words_by_ref()\n+if ! type _get_comp_words_by_ref >/dev/null 2>&1; then\n+_get_comp_words_by_ref ()\n {\n+\tlocal words_ cword_\n \tlocal exclude i j first\n+\n \t# Which word separators to exclude?\n-\texclude=\"${1//[^$COMP_WORDBREAKS]}\"\n+\texclude=\"${COMP_WORDBREAKS//[^=:]}\"\n \tcword_=$COMP_CWORD\n \tif [ -z \"$exclude\" ]; then\n \t\twords_=(\"${COMP_WORDS[@]}\")\n-\t\treturn\n-\tfi\n-\t# List of word completion separators has shrunk;\n-\t# re-assemble words to complete.\n-\tfor ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do\n-\t\t# Append each nonempty word consisting of just\n-\t\t# word separator characters to the current word.\n-\t\tfirst=t\n-\t\twhile\n-\t\t\t[ $i -gt 0 ] &&\n-\t\t\t[ -n \"${COMP_WORDS[$i]}\" ] &&\n-\t\t\t# word consists of excluded word separators\n-\t\t\t[ \"${COMP_WORDS[$i]//[^$exclude]}\" = \"${COMP_WORDS[$i]}\" ]\n-\t\tdo\n-\t\t\t# Attach to the previous token,\n-\t\t\t# unless the previous token is the command name.\n-\t\t\tif [ $j -ge 2 ] && [ -n \"$first\" ]; then\n-\t\t\t\t((j--))\n-\t\t\tfi\n-\t\t\tfirst=\n+\telse\n+\t\t# List of word completion separators has shrunk;\n+\t\t# re-assemble words to complete.\n+\t\tfor ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do\n+\t\t\t# Append each nonempty word consisting of just\n+\t\t\t# word separator characters to the current word.\n+\t\t\tfirst=t\n+\t\t\twhile\n+\t\t\t\t[ $i -gt 0 ] &&\n+\t\t\t\t[ -n \"${COMP_WORDS[$i]}\" ] &&\n+\t\t\t\t# word consists of excluded word separators\n+\t\t\t\t[ \"${COMP_WORDS[$i]//[^$exclude]}\" = \"${COMP_WORDS[$i]}\" ]\n+\t\t\tdo\n+\t\t\t\t# Attach to the previous token,\n+\t\t\t\t# unless the previous token is the command name.\n+\t\t\t\tif [ $j -ge 2 ] && [ -n \"$first\" ]; then\n+\t\t\t\t\t((j--))\n+\t\t\t\tfi\n+\t\t\t\tfirst=\n+\t\t\t\twords_[$j]=${words_[j]}${COMP_WORDS[i]}\n+\t\t\t\tif [ $i = $COMP_CWORD ]; then\n+\t\t\t\t\tcword_=$j\n+\t\t\t\tfi\n+\t\t\t\tif (($i < ${#COMP_WORDS[@]} - 1)); then\n+\t\t\t\t\t((i++))\n+\t\t\t\telse\n+\t\t\t\t\t# Done.\n+\t\t\t\t\tbreak 2\n+\t\t\t\tfi\n+\t\t\tdone\n \t\t\twords_[$j]=${words_[j]}${COMP_WORDS[i]}\n \t\t\tif [ $i = $COMP_CWORD ]; then\n \t\t\t\tcword_=$j\n \t\t\tfi\n-\t\t\tif (($i < ${#COMP_WORDS[@]} - 1)); then\n-\t\t\t\t((i++))\n-\t\t\telse\n-\t\t\t\t# Done.\n-\t\t\t\treturn\n-\t\t\tfi\n \t\tdone\n-\t\twords_[$j]=${words_[j]}${COMP_WORDS[i]}\n-\t\tif [ $i = $COMP_CWORD ]; then\n-\t\t\tcword_=$j\n-\t\tfi\n-\tdone\n-}\n+\tfi\n \n-if ! type _get_comp_words_by_ref >/dev/null 2>&1; then\n-_get_comp_words_by_ref ()\n-{\n-\tlocal words_ cword_\n-\t__git_reassemble_comp_words_by_ref \"=:\"\n \tcword=$cword_\n \tcur=${words_[cword]}\n \tprev=${words_[cword-1]}\n-- \n2.30.0\n\n"},{"id":"413262","messageId":"20210101021622.798041-33-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 32/47] completion: zsh: simplify __gitcomp_direct","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:07Z","receivedAt":"2021-01-01T02:17:45Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Not much different from __gitcomp_nl.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex d5ec8a1417..6afcf1810b 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -89,9 +89,7 @@ __gitcomp_opts ()\n \n __gitcomp_direct ()\n {\n-\temulate -L zsh\n-\n-\tcompadd -Q -S '' -- ${(f)1} && _ret=0\n+\t__gitcomp_nl \"$1\" \"\" \"\" \"\"\n }\n \n __gitcomp_nl ()\n-- \n2.30.0\n\n"},{"id":"413263","messageId":"20210101021622.798041-41-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 40/47] completion: bash: cleanup _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:15Z","receivedAt":"2021-01-01T02:17:45Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Remove temporary variables.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 040391f881..9918998848 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -341,14 +341,13 @@ __git_dequote ()\n if ! type _get_comp_words_by_ref >/dev/null 2>&1; then\n _get_comp_words_by_ref ()\n {\n-\tlocal words_ cword_\n \tlocal exclude i j first\n \n \t# Which word separators to exclude?\n \texclude=\"${COMP_WORDBREAKS//[^=:]}\"\n-\tcword_=$COMP_CWORD\n+\tcword=$COMP_CWORD\n \tif [ -z \"$exclude\" ]; then\n-\t\twords_=(\"${COMP_WORDS[@]}\")\n+\t\twords=(\"${COMP_WORDS[@]}\")\n \telse\n \t\t# List of word completion separators has shrunk;\n \t\t# re-assemble words to complete.\n@@ -368,9 +367,9 @@ _get_comp_words_by_ref ()\n \t\t\t\t\t((j--))\n \t\t\t\tfi\n \t\t\t\tfirst=\n-\t\t\t\twords_[$j]=${words_[j]}${COMP_WORDS[i]}\n+\t\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n \t\t\t\tif [ $i = $COMP_CWORD ]; then\n-\t\t\t\t\tcword_=$j\n+\t\t\t\t\tcword=$j\n \t\t\t\tfi\n \t\t\t\tif (($i < ${#COMP_WORDS[@]} - 1)); then\n \t\t\t\t\t((i++))\n@@ -379,17 +378,15 @@ _get_comp_words_by_ref ()\n \t\t\t\t\tbreak 2\n \t\t\t\tfi\n \t\t\tdone\n-\t\t\twords_[$j]=${words_[j]}${COMP_WORDS[i]}\n+\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n \t\t\tif [ $i = $COMP_CWORD ]; then\n-\t\t\t\tcword_=$j\n+\t\t\t\tcword=$j\n \t\t\tfi\n \t\tdone\n \tfi\n \n-\tcword=$cword_\n-\tcur=${words_[cword]}\n-\tprev=${words_[cword-1]}\n-\twords=(\"${words_[@]}\")\n+\tcur=${words[cword]}\n+\tprev=${words[cword-1]}\n }\n fi\n \n-- \n2.30.0\n\n"},{"id":"413264","messageId":"20210101021622.798041-19-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 18/47] completion: zsh: add excluded options","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:53Z","receivedAt":"2021-01-01T02:17:46Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Add more excluded options, for example: --bare excludes --git-dir.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 17 +++++++++--------\n 1 file changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 073f7d91d8..7cb0f33209 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -218,15 +218,16 @@ __git_zsh_main ()\n \torig_words=( ${words[@]} )\n \n \t_arguments -C \\\n-\t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n-\t\t'(-p --paginate)--no-pager[do not pipe git output into a pager]' \\\n-\t\t'--git-dir=[set the path to the repository]: :_directories' \\\n-\t\t'--bare[treat the repository as a bare repository]' \\\n+\t\t'(-p --paginate -P --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n+\t\t'(-p --paginate -P --no-pager)'{-P,--no-pager}'[do not pipe git output into a pager]' \\\n+\t\t'(--bare)--git-dir=[set the path to the repository]: :_directories' \\\n+\t\t'(--git-dir)--bare[treat the repository as a bare repository]' \\\n \t\t'(- :)--version[prints the git suite version]' \\\n-\t\t'--exec-path=[path to where your core git programs are installed]:: :_directories' \\\n-\t\t'--html-path[print the path where git''s HTML documentation is installed]' \\\n-\t\t'--info-path[print the path where the Info files are installed]' \\\n-\t\t'--man-path[print the manpath (see `man(1)`) for the man pages]' \\\n+\t\t'--exec-path=[path to where your core git programs are installed]: :_directories' \\\n+\t\t'(- :)--exec-path[print the path where your core git programs are installed]' \\\n+\t\t'(- :)--html-path[print the path where git''s HTML documentation is installed]' \\\n+\t\t'(- :)--info-path[print the path where the Info files are installed]' \\\n+\t\t'(- :)--man-path[print the manpath (see `man(1)`) for the man pages]' \\\n \t\t'--work-tree=[set the path to the working tree]: :_directories' \\\n \t\t'--namespace=[set the git namespace]:' \\\n \t\t'--no-replace-objects[do not use replacement refs to replace git objects]' \\\n-- \n2.30.0\n\n"},{"id":"413265","messageId":"20210101021622.798041-21-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 20/47] completion: factor out check in __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:55Z","receivedAt":"2021-01-01T02:17:48Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This way we can reorganize the rest of the function.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 6 ++++--\n contrib/completion/git-completion.zsh  | 4 ++--\n 2 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ec62c11fe5..ff5d29bf36 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -321,9 +321,11 @@ __gitcomp ()\n {\n \tlocal cur_=\"${3-$cur}\"\n \n+\tif [[ \"$cur_\" == *= ]]; then\n+\t\treturn\n+\tfi\n+\n \tcase \"$cur_\" in\n-\t*=)\n-\t\t;;\n \t--no-*)\n \t\tlocal c i=0 IFS=$' \\t\\n'\n \t\tfor c in $1; do\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex d754086877..090c644b71 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -55,9 +55,9 @@ __gitcomp ()\n \n \tlocal cur_=\"${3-$cur}\"\n \n+\t[[ \"$cur_\" == *= ]] && return\n+\n \tcase \"$cur_\" in\n-\t*=)\n-\t\t;;\n \t--no-*)\n \t\tlocal c IFS=$' \\t\\n'\n \t\tlocal -a array\n-- \n2.30.0\n\n"},{"id":"413266","messageId":"20210101021622.798041-23-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 22/47] completion: refactor __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:57Z","receivedAt":"2021-01-01T02:17:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We have to chunks of code doing exactly the same. There's no need for\nthat.\n\nNo functional changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 52 +++++++++-----------------\n contrib/completion/git-completion.zsh  | 52 ++++++++------------------\n 2 files changed, 34 insertions(+), 70 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 0522750b9f..b356e3c86f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -325,44 +325,28 @@ __gitcomp ()\n \t\treturn\n \tfi\n \n-\tcase \"$cur_\" in\n-\t--no-*)\n-\t\tlocal c i=0 IFS=$' \\t\\n'\n-\t\tfor c in $1; do\n-\t\t\tif [[ $c == \"--\" ]]; then\n+\tlocal c i=0 IFS=$' \\t\\n'\n+\tfor c in $1; do\n+\t\tif [[ $c == \"--\" ]]; then\n+\t\t\tif [[ \"$cur_\" == --no-* ]]; then\n \t\t\t\tcontinue\n \t\t\tfi\n-\t\t\tc=\"$c${4-}\"\n-\t\t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\t\tcase $c in\n-\t\t\t\t*=|*.) ;;\n-\t\t\t\t*) c=\"$c \" ;;\n-\t\t\t\tesac\n-\t\t\t\tCOMPREPLY[i++]=\"${2-}$c\"\n-\t\t\tfi\n-\t\tdone\n-\t\t;;\n-\t*)\n-\t\tlocal c i=0 IFS=$' \\t\\n'\n-\t\tfor c in $1; do\n-\t\t\tif [[ $c == \"--\" ]]; then\n-\t\t\t\tc=\"--no-...${4-}\"\n-\t\t\t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\t\t\tCOMPREPLY[i++]=\"${2-}$c \"\n-\t\t\t\tfi\n-\t\t\t\tbreak\n-\t\t\tfi\n-\t\t\tc=\"$c${4-}\"\n+\n+\t\t\tc=\"--no-...${4-}\"\n \t\t\tif [[ $c == \"$cur_\"* ]]; then\n-\t\t\t\tcase $c in\n-\t\t\t\t*=|*.) ;;\n-\t\t\t\t*) c=\"$c \" ;;\n-\t\t\t\tesac\n-\t\t\t\tCOMPREPLY[i++]=\"${2-}$c\"\n+\t\t\t\tCOMPREPLY[i++]=\"${2-}$c \"\n \t\t\tfi\n-\t\tdone\n-\t\t;;\n-\tesac\n+\t\t\tbreak\n+\t\tfi\n+\t\tc=\"$c${4-}\"\n+\t\tif [[ $c == \"$cur_\"* ]]; then\n+\t\t\tcase $c in\n+\t\t\t*=|*.) ;;\n+\t\t\t*) c=\"$c \" ;;\n+\t\t\tesac\n+\t\t\tCOMPREPLY[i++]=\"${2-}$c\"\n+\t\tfi\n+\tdone\n }\n \n # Clear the variables caching builtins' options when (re-)sourcing\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 8db7d0693d..fbd03a0180 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -57,42 +57,22 @@ __gitcomp ()\n \n \t[[ \"$cur_\" == *= ]] && return\n \n-\tcase \"$cur_\" in\n-\t--no-*)\n-\t\tlocal c IFS=$' \\t\\n'\n-\t\tlocal -a array\n-\t\tfor c in ${=1}; do\n-\t\t\tif [[ $c == \"--\" ]]; then\n-\t\t\t\tcontinue\n-\t\t\tfi\n-\t\t\tc=\"$c${4-}\"\n-\t\t\tcase $c in\n-\t\t\t*=|*.) ;;\n-\t\t\t*) c=\"$c \" ;;\n-\t\t\tesac\n-\t\t\tarray+=(\"$c\")\n-\t\tdone\n-\t\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n-\t\t;;\n-\t*)\n-\t\tlocal c IFS=$' \\t\\n'\n-\t\tlocal -a array\n-\t\tfor c in ${=1}; do\n-\t\t\tif [[ $c == \"--\" ]]; then\n-\t\t\t\tc=\"--no-...${4-}\"\n-\t\t\t\tarray+=(\"$c \")\n-\t\t\t\tbreak\n-\t\t\tfi\n-\t\t\tc=\"$c${4-}\"\n-\t\t\tcase $c in\n-\t\t\t*=|*.) ;;\n-\t\t\t*) c=\"$c \" ;;\n-\t\t\tesac\n-\t\t\tarray+=(\"$c\")\n-\t\tdone\n-\t\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n-\t\t;;\n-\tesac\n+\tlocal c IFS=$' \\t\\n'\n+\tlocal -a array\n+\tfor c in ${=1}; do\n+\t\tif [[ $c == \"--\" ]]; then\n+\t\t\t[[ \"$cur_\" == --no-* ]] && continue\n+\t\t\tarray+=(\"--no-...${4-} \")\n+\t\t\tbreak\n+\t\tfi\n+\t\tc=\"$c${4-}\"\n+\t\tcase $c in\n+\t\t*=|*.) ;;\n+\t\t*) c=\"$c \" ;;\n+\t\tesac\n+\t\tarray+=(\"$c\")\n+\tdone\n+\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n }\n \n __gitcomp_direct ()\n-- \n2.30.0\n\n"},{"id":"413267","messageId":"20210101021622.798041-25-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 24/47] completion: bash: change suffix check in __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:15:59Z","receivedAt":"2021-01-01T02:17:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We don't match the prefix, we shouldn't match the suffix either.\n\nThere are no functional changes since all the callers that add a suffix\nadd an =, and if $cur_ ended with that suffix, we would return\nimmediately.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 00a78039b8..1f0728ae52 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -337,8 +337,8 @@ __gitcomp ()\n \t\t\tfi\n \t\t\tbreak\n \t\tfi\n-\t\tc=\"$c${4-}\"\n \t\tif [[ $c == \"$cur_\"* ]]; then\n+\t\t\tc=\"$c${4-}\"\n \t\t\tcase $c in\n \t\t\t*=|*.) ;;\n \t\t\t*) c=\"$c \" ;;\n-- \n2.30.0\n\n"},{"id":"413268","messageId":"20210101021622.798041-45-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 44/47] completion: bash: improve function detection","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:19Z","receivedAt":"2021-01-01T02:17:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":" 1. We should quote the argument\n 2. We don't need two redirections\n 3. A safeguard for arguments (-a) would be good\n\nSuggested-by: René Scharfe <l.s.r@web.de>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 4bd3e706ac..11a9433363 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3201,7 +3201,7 @@ __git_support_parseopt_helper () {\n }\n \n __git_have_func () {\n-\tdeclare -f $1 >/dev/null 2>/dev/null\n+\tdeclare -f -- \"$1\" >/dev/null 2>&1\n }\n \n __git_complete_command () {\n-- \n2.30.0\n\n"},{"id":"413269","messageId":"20210101021622.798041-27-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 26/47] completion: bash: simplify config_variable_name","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:01Z","receivedAt":"2021-01-01T02:17:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Now that we can actually pass a suffix to __gitcomp function, and it\ndoes the right thing, all the functions can receive the same suffix.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 4eea322366..73c9a81405 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2569,7 +2569,7 @@ __git_complete_config_variable_value ()\n #                 subsections) instead of the default space.\n __git_complete_config_variable_name ()\n {\n-\tlocal cur_=\"$cur\" sfx\n+\tlocal cur_=\"$cur\" sfx=\" \"\n \n \twhile test $# != 0; do\n \t\tcase \"$1\" in\n@@ -2591,7 +2591,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_direct \"$(__git_heads \"$pfx\" \"$cur_\" \".\")\"\n-\t\t__gitcomp_nl $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"${sfx- }\"\n+\t\t__gitcomp_nl $'autoSetupMerge\\nautoSetupRebase\\n' \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n \t\t;;\n \tguitool.*.*)\n@@ -2625,7 +2625,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__git_compute_all_commands\n-\t\t__gitcomp_nl \"$__git_all_commands\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n+\t\t__gitcomp_nl \"$__git_all_commands\" \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n \t\t;;\n \tremote.*.*)\n@@ -2641,7 +2641,7 @@ __git_complete_config_variable_name ()\n \t\tlocal pfx=\"${cur_%.*}.\"\n \t\tcur_=\"${cur_#*.}\"\n \t\t__gitcomp_nl \"$(__git_remotes)\" \"$pfx\" \"$cur_\" \".\"\n-\t\t__gitcomp_nl \"pushDefault\" \"$pfx\" \"$cur_\" \"${sfx- }\"\n+\t\t__gitcomp_nl \"pushDefault\" \"$pfx\" \"$cur_\" \"$sfx\"\n \t\treturn\n \t\t;;\n \turl.*.*)\n-- \n2.30.0\n\n"},{"id":"413270","messageId":"20210101021622.798041-46-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 45/47] test: completion: add tests for __git_complete","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:20Z","receivedAt":"2021-01-01T02:17:55Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Even though the function was marked as not public, it's already used in\nthe wild.\n\nWe should at least test basic functionality.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 8 ++++++++\n 1 file changed, 8 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 6366242408..01984692bb 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2379,4 +2379,12 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \tverbose test -z \"$__gitcomp_builtin_notes_edit\"\n '\n \n+test_expect_success '__git_complete' '\n+\tunset -f __git_wrap__git_main &&\n+\t__git_complete foo __git_main &&\n+\t__git_have_func __git_wrap__git_main &&\n+\t__git_complete gf _git_fetch &&\n+\t__git_have_func __git_wrap_git_fetch\n+'\n+\n test_done\n-- \n2.30.0\n\n"},{"id":"413271","messageId":"20210101021622.798041-48-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 47/47] completion: zsh: add higher-priority location","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:22Z","receivedAt":"2021-01-01T02:17:57Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"bash-completion looks in /usr/local/share first, we should too.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 43b7c1b210..0024fd742c 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -35,6 +35,7 @@ if [ -z \"$script\" ]; then\n \tlocations=(\n \t\t\"$(dirname ${funcsourcetrace[1]%:*})\"/git-completion.bash\n \t\t\"$HOME/.local/share/bash-completion/completions/git\"\n+\t\t'/usr/local/share/bash-completion/completions/git'\n \t\t\"$bash_completion/git\"\n \t\t'/etc/bash_completion.d/git' # old debian\n \t\t)\n-- \n2.30.0\n\n"},{"id":"413272","messageId":"20210101021622.798041-43-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 42/47] completion: bash: rename _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:17Z","receivedAt":"2021-01-01T02:17:58Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's only used in one place, rename it, and use it even if\nbash-completion's more inefficient version of _get_comp_words_by_ref()\nis available.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 184 ++++++++++++-------------\n t/t9902-completion.sh                  |   2 +-\n 2 files changed, 92 insertions(+), 94 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex d481824a7f..59f1563674 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -298,98 +298,6 @@ __git_dequote ()\n \tdone\n }\n \n-# The following function is based on code from:\n-#\n-#   bash_completion - programmable completion functions for bash 3.2+\n-#\n-#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>\n-#             © 2009-2010, Bash Completion Maintainers\n-#                     <bash-completion-devel@lists.alioth.debian.org>\n-#\n-#   This program is free software; you can redistribute it and/or modify\n-#   it under the terms of the GNU General Public License as published by\n-#   the Free Software Foundation; either version 2, or (at your option)\n-#   any later version.\n-#\n-#   This program is distributed in the hope that it will be useful,\n-#   but WITHOUT ANY WARRANTY; without even the implied warranty of\n-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n-#   GNU General Public License for more details.\n-#\n-#   You should have received a copy of the GNU General Public License\n-#   along with this program; if not, see <http://www.gnu.org/licenses/>.\n-#\n-#   The latest version of this software can be obtained here:\n-#\n-#   http://bash-completion.alioth.debian.org/\n-#\n-#   RELEASE: 2.x\n-\n-# This function reorganizes the words on the command line to be processed by\n-# the rest of the script.\n-#\n-# This is roughly equivalent to going back in time and setting\n-# COMP_WORDBREAKS to exclude '=' and ':'.  The intent is to\n-# make option types like --date=<type> and <rev>:<path> easy to\n-# recognize by treating each shell word as a single token.\n-#\n-# It is best not to set COMP_WORDBREAKS directly because the value is\n-# shared with other completion scripts.  By the time the completion\n-# function gets called, COMP_WORDS has already been populated so local\n-# changes to COMP_WORDBREAKS have no effect.\n-\n-if ! type _get_comp_words_by_ref >/dev/null 2>&1; then\n-_get_comp_words_by_ref ()\n-{\n-\tlocal exclude i j first\n-\n-\t# Which word separators to exclude?\n-\texclude=\"${COMP_WORDBREAKS//[^=:]}\"\n-\tcword=$COMP_CWORD\n-\tif [ -n \"$exclude\" ]; then\n-\t\t# List of word completion separators has shrunk;\n-\t\t# re-assemble words to complete.\n-\t\tfor ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do\n-\t\t\t# Append each nonempty word consisting of just\n-\t\t\t# word separator characters to the current word.\n-\t\t\tfirst=t\n-\t\t\twhile\n-\t\t\t\t[ $i -gt 0 ] &&\n-\t\t\t\t[ -n \"${COMP_WORDS[$i]}\" ] &&\n-\t\t\t\t# word consists of excluded word separators\n-\t\t\t\t[ \"${COMP_WORDS[$i]//[^$exclude]}\" = \"${COMP_WORDS[$i]}\" ]\n-\t\t\tdo\n-\t\t\t\t# Attach to the previous token,\n-\t\t\t\t# unless the previous token is the command name.\n-\t\t\t\tif [ $j -ge 2 ] && [ -n \"$first\" ]; then\n-\t\t\t\t\t((j--))\n-\t\t\t\tfi\n-\t\t\t\tfirst=\n-\t\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n-\t\t\t\tif [ $i = $COMP_CWORD ]; then\n-\t\t\t\t\tcword=$j\n-\t\t\t\tfi\n-\t\t\t\tif (($i < ${#COMP_WORDS[@]} - 1)); then\n-\t\t\t\t\t((i++))\n-\t\t\t\telse\n-\t\t\t\t\t# Done.\n-\t\t\t\t\tbreak 2\n-\t\t\t\tfi\n-\t\t\tdone\n-\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n-\t\t\tif [ $i = $COMP_CWORD ]; then\n-\t\t\t\tcword=$j\n-\t\t\tfi\n-\t\tdone\n-\telse\n-\t\twords=(\"${COMP_WORDS[@]}\")\n-\tfi\n-\n-\tcur=${words[cword]}\n-\tprev=${words[cword-1]}\n-}\n-fi\n-\n # Clear the variables caching builtins' options when (re-)sourcing\n # the completion script.\n if [[ -n ${ZSH_VERSION-} ]]; then\n@@ -3420,10 +3328,100 @@ if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then\n \treturn\n fi\n \n+# The following function is based on code from:\n+#\n+#   bash_completion - programmable completion functions for bash 3.2+\n+#\n+#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>\n+#             © 2009-2010, Bash Completion Maintainers\n+#                     <bash-completion-devel@lists.alioth.debian.org>\n+#\n+#   This program is free software; you can redistribute it and/or modify\n+#   it under the terms of the GNU General Public License as published by\n+#   the Free Software Foundation; either version 2, or (at your option)\n+#   any later version.\n+#\n+#   This program is distributed in the hope that it will be useful,\n+#   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#   GNU General Public License for more details.\n+#\n+#   You should have received a copy of the GNU General Public License\n+#   along with this program; if not, see <http://www.gnu.org/licenses/>.\n+#\n+#   The latest version of this software can be obtained here:\n+#\n+#   http://bash-completion.alioth.debian.org/\n+#\n+#   RELEASE: 2.x\n+\n+# This function reorganizes the words on the command line to be processed by\n+# the rest of the script.\n+#\n+# This is roughly equivalent to going back in time and setting\n+# COMP_WORDBREAKS to exclude '=' and ':'.  The intent is to\n+# make option types like --date=<type> and <rev>:<path> easy to\n+# recognize by treating each shell word as a single token.\n+#\n+# It is best not to set COMP_WORDBREAKS directly because the value is\n+# shared with other completion scripts.  By the time the completion\n+# function gets called, COMP_WORDS has already been populated so local\n+# changes to COMP_WORDBREAKS have no effect.\n+\n+__git_get_comp_words_by_ref ()\n+{\n+\tlocal exclude i j first\n+\n+\t# Which word separators to exclude?\n+\texclude=\"${COMP_WORDBREAKS//[^=:]}\"\n+\tcword=$COMP_CWORD\n+\tif [ -n \"$exclude\" ]; then\n+\t\t# List of word completion separators has shrunk;\n+\t\t# re-assemble words to complete.\n+\t\tfor ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do\n+\t\t\t# Append each nonempty word consisting of just\n+\t\t\t# word separator characters to the current word.\n+\t\t\tfirst=t\n+\t\t\twhile\n+\t\t\t\t[ $i -gt 0 ] &&\n+\t\t\t\t[ -n \"${COMP_WORDS[$i]}\" ] &&\n+\t\t\t\t# word consists of excluded word separators\n+\t\t\t\t[ \"${COMP_WORDS[$i]//[^$exclude]}\" = \"${COMP_WORDS[$i]}\" ]\n+\t\t\tdo\n+\t\t\t\t# Attach to the previous token,\n+\t\t\t\t# unless the previous token is the command name.\n+\t\t\t\tif [ $j -ge 2 ] && [ -n \"$first\" ]; then\n+\t\t\t\t\t((j--))\n+\t\t\t\tfi\n+\t\t\t\tfirst=\n+\t\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n+\t\t\t\tif [ $i = $COMP_CWORD ]; then\n+\t\t\t\t\tcword=$j\n+\t\t\t\tfi\n+\t\t\t\tif (($i < ${#COMP_WORDS[@]} - 1)); then\n+\t\t\t\t\t((i++))\n+\t\t\t\telse\n+\t\t\t\t\t# Done.\n+\t\t\t\t\tbreak 2\n+\t\t\t\tfi\n+\t\t\tdone\n+\t\t\twords[$j]=${words[j]}${COMP_WORDS[i]}\n+\t\t\tif [ $i = $COMP_CWORD ]; then\n+\t\t\t\tcword=$j\n+\t\t\tfi\n+\t\tdone\n+\telse\n+\t\twords=(\"${COMP_WORDS[@]}\")\n+\tfi\n+\n+\tcur=${words[cword]}\n+\tprev=${words[cword-1]}\n+}\n+\n __git_func_wrap ()\n {\n \tlocal cur words cword prev\n-\t_get_comp_words_by_ref -n =: cur words cword prev\n+\t__git_get_comp_words_by_ref\n \t$1\n }\n \ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 363d8817af..6366242408 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -38,7 +38,7 @@ GIT_TESTING_PORCELAIN_COMMAND_LIST='add checkout rebase'\n # We don't need this function to actually join words or do anything special.\n # Also, it's cleaner to avoid touching bash's internal completion variables.\n # So let's override it with a minimal version for testing purposes.\n-_get_comp_words_by_ref ()\n+__git_get_comp_words_by_ref ()\n {\n \tcword=$_cword\n \tcur=${_words[cword]}\n-- \n2.30.0\n\n"},{"id":"413273","messageId":"20210101021622.798041-35-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 34/47] completion: zsh: fix direct quoting","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:09Z","receivedAt":"2021-01-01T02:18:01Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Apparently using \"compadd -Q\" is almost always wrong, we want zsh to add\nquoting when necessary. However, if we remove the -Q option, that would\nmake zsh add an extra \"\\ \" at the end of some completions.\n\nWe can manually remove the spaces from the completions that have them,\nand then add the suffix with the -S option, thus there's no more need\nfor the -Q option.\n\nThis makes completions like \"stash@{0}\" complete correctly:\n\n  git stash show <tab>\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 9 ++++++---\n 1 file changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 3665167b3f..2faf435087 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -54,7 +54,7 @@ __gitcomp ()\n \temulate -L zsh\n \n \tlocal IFS=$' \\t\\n'\n-\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n+\tcompadd -S \"${4- }\" -p \"${2-}\" -- ${=1} && _ret=0\n }\n \n __gitcomp_opts ()\n@@ -84,14 +84,17 @@ __gitcomp_opts ()\n \t\tfi\n \t\tarray+=(\"$c$sfx\")\n \tdone\n-\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n+\tcompadd -S '' -p \"${2-}\" -a -- array && _ret=0\n }\n \n __gitcomp_nl ()\n {\n \temulate -L zsh\n \n-\tcompadd -Q -S \"${4- }\" -p \"${2-}\" -- ${(f)1} && _ret=0\n+\t# words that don't end up in space\n+\tcompadd -p \"${2-}\" -S \"${4- }\" -q -- ${${(f)1}:#*\\ } && _ret=0\n+\t# words that end in space\n+\tcompadd -p \"${2-}\" -S \" ${4- }\" -q -- ${${(M)${(f)1}:#*\\ }% } && _ret=0\n }\n \n __gitcomp_file ()\n-- \n2.30.0\n\n"},{"id":"413274","messageId":"20210101021622.798041-42-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 41/47] completion: bash: trivial cleanup","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:16Z","receivedAt":"2021-01-01T02:18:11Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The most typical case first (COMP_WORDBREAKS contains our wanted words).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 9918998848..d481824a7f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -346,9 +346,7 @@ _get_comp_words_by_ref ()\n \t# Which word separators to exclude?\n \texclude=\"${COMP_WORDBREAKS//[^=:]}\"\n \tcword=$COMP_CWORD\n-\tif [ -z \"$exclude\" ]; then\n-\t\twords=(\"${COMP_WORDS[@]}\")\n-\telse\n+\tif [ -n \"$exclude\" ]; then\n \t\t# List of word completion separators has shrunk;\n \t\t# re-assemble words to complete.\n \t\tfor ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do\n@@ -383,6 +381,8 @@ _get_comp_words_by_ref ()\n \t\t\t\tcword=$j\n \t\t\tfi\n \t\tdone\n+\telse\n+\t\twords=(\"${COMP_WORDS[@]}\")\n \tfi\n \n \tcur=${words[cword]}\n-- \n2.30.0\n\n"},{"id":"413275","messageId":"20210101021622.798041-44-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 43/47] completion: bash: add __git_have_func helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:18Z","receivedAt":"2021-01-01T02:18:15Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This makes the code more readable, and also will help when new code\nwants to do similar checks.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 59f1563674..4bd3e706ac 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3200,15 +3200,19 @@ __git_support_parseopt_helper () {\n \tesac\n }\n \n+__git_have_func () {\n+\tdeclare -f $1 >/dev/null 2>/dev/null\n+}\n+\n __git_complete_command () {\n \tlocal command=\"$1\"\n \tlocal completion_func=\"_git_${command//-/_}\"\n-\tif ! declare -f $completion_func >/dev/null 2>/dev/null &&\n-\t\tdeclare -f _completion_loader >/dev/null 2>/dev/null\n+\tif ! __git_have_func $completion_func &&\n+\t\t__git_have_func _completion_loader\n \tthen\n \t\t_completion_loader \"git-$command\"\n \tfi\n-\tif declare -f $completion_func >/dev/null 2>/dev/null\n+\tif __git_have_func $completion_func\n \tthen\n \t\t$completion_func\n \t\treturn 0\n-- \n2.30.0\n\n"},{"id":"413276","messageId":"20210101021622.798041-47-felipe.contreras@gmail.com","threadId":"54913","inReplyTo":"20210101021622.798041-1-felipe.contreras@gmail.com","subject":"[PATCH 46/47] completion: add proper public __git_complete","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-01T02:16:21Z","receivedAt":"2021-01-01T02:18:22Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"When __git_complete was introduced, it was meant to be temporarily, while\na proper guideline for public shell functions was established\n(tentatively _GIT_complete), but since that never happened, people\nin the wild started to use __git_complete, even though it was marked as\nnot public.\n\nEight years is more than enough wait, let's mark this function as\npublic, and make it a bit more user-friendly.\n\nSo that instead of doing:\n\n  __git_complete gk __gitk_main\n\nThe user can do:\n\n  __git_complete gk gitk\n\nAnd instead of:\n\n  __git_complete gf _git_fetch\n\nDo:\n\n  __git_complete gf git_fetch\n\nBackwards compatibility is maintained.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 40 +++++++++++++++++++++-----\n t/t9902-completion.sh                  | 14 ++++++++-\n 2 files changed, 46 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 11a9433363..a0e5752217 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -29,6 +29,15 @@\n # tell the completion to use commit completion.  This also works with aliases\n # of form \"!sh -c '...'\".  For example, \"!sh -c ': git commit ; ... '\".\n #\n+# If you have a command that is not part of git, but you would still\n+# like completion, you can use __git_complete:\n+#\n+#   __git_complete gl git_log\n+#\n+# Or if it's a main command (i.e. git or gitk):\n+#\n+#   __git_complete gk gitk\n+#\n # Compatible with bash 3.2.57.\n #\n # You can set the following environment variables to influence the behavior of\n@@ -3429,10 +3438,7 @@ __git_func_wrap ()\n \t$1\n }\n \n-# Setup completion for certain functions defined above by setting common\n-# variables and workarounds.\n-# This is NOT a public function; use at your own risk.\n-__git_complete ()\n+___git_complete ()\n {\n \tlocal wrapper=\"__git_wrap${2}\"\n \teval \"$wrapper () { __git_func_wrap $2 ; }\"\n@@ -3440,13 +3446,33 @@ __git_complete ()\n \t\t|| complete -o default -o nospace -F $wrapper $1\n }\n \n-__git_complete git __git_main\n-__git_complete gitk __gitk_main\n+# Setup the completion for git commands\n+# 1: command or alias\n+# 2: function to call (e.g. `git`, `gitk`, `git_fetch`)\n+__git_complete ()\n+{\n+\tlocal func\n+\n+\tif __git_have_func $2; then\n+\t\tfunc=$2\n+\telif __git_have_func __$2_main; then\n+\t\tfunc=__$2_main\n+\telif __git_have_func _$2; then\n+\t\tfunc=_$2\n+\telse\n+\t\techo \"ERROR: could not find function '$2'\" 1>&2\n+\t\treturn 1\n+\tfi\n+\t___git_complete $1 $func\n+}\n+\n+___git_complete git __git_main\n+___git_complete gitk __gitk_main\n \n # The following are necessary only for Cygwin, and only are needed\n # when the user has tab-completed the executable name and consequently\n # included the '.exe' suffix.\n #\n if [ \"$OSTYPE\" = cygwin ]; then\n-\t__git_complete git.exe __git_main\n+\t___git_complete git.exe __git_main\n fi\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 01984692bb..b9490637f9 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2381,10 +2381,22 @@ test_expect_success 'sourcing the completion script clears cached --options' '\n \n test_expect_success '__git_complete' '\n \tunset -f __git_wrap__git_main &&\n+\n \t__git_complete foo __git_main &&\n \t__git_have_func __git_wrap__git_main &&\n+\tunset -f __git_wrap__git_main &&\n+\n \t__git_complete gf _git_fetch &&\n-\t__git_have_func __git_wrap_git_fetch\n+\t__git_have_func __git_wrap_git_fetch &&\n+\n+\t__git_complete foo git &&\n+\t__git_have_func __git_wrap__git_main &&\n+\tunset -f __git_wrap__git_main &&\n+\n+\t__git_complete gd git_diff &&\n+\t__git_have_func __git_wrap_git_diff &&\n+\n+\ttest_must_fail __git_complete ga missing\n '\n \n test_done\n-- \n2.30.0\n\n"}]}