{"thread":{"id":"59514","subject":"[PATCH v7 02/49] completion: bash: trivial cleanup","startedAt":"2023-04-01T08:46:35Z","lastAt":"2023-04-01T08:50:01Z","messageCount":50,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":7,"patchTotal":49},"messages":[{"id":"474550","messageId":"20230401084626.304356-3-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 02/49] completion: bash: trivial cleanup","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:39Z","receivedAt":"2023-04-01T08:46:35Z","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 | 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 dc95c34cc8..45eaea57d5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3565,8 +3565,7 @@ fi\n \n __git_func_wrap ()\n {\n-\tlocal cur words cword prev\n-\tlocal __git_cmd_idx=0\n+\tlocal cur words cword prev __git_cmd_idx=0\n \t_get_comp_words_by_ref -n =: cur words cword prev\n \t$1\n }\n-- \n2.33.0\n\n"},{"id":"474551","messageId":"20230401084626.304356-1-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":null,"subject":"[PATCH v7 00/49] completion: git-completion 2.0 patches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:37Z","receivedAt":"2023-04-01T08:46:36Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This patch series revamps the completion code to git-completion 2.0.\n\nIt's meant to be applied on top of the zsh completion test series [1].\n\nThe zsh code delta between upstream and git-completion 2.0 results in 12\nout of 13 failing tests now passing. This patch series now makes that\nclear.\n\nAdditionally, it adds and fixes one bash completion test pending since\n2020 [2].\n\nThis patch series started being relatively small (10 patches) [3], but\nupstream has never merged them, so it's now 51 patches.\n\nOne patch has been merged to master, so that's progress I guess.\n\nHere's a summary of the differences between upstream and git-completion:\n\n# For zsh\n * Fix alias regression\n * Fix main option handling\n * Fix generic completions\n * Fix option relationships\n * Add improved removable suffix\n * Fix suboptions\n * Fix -C handling\n * Fix -c handling\n * Fix configurations with value (e1e00089da)\n\n# Other\n * Fix `COMP_WORDBREAKS` handling\n * Plenty of reorganizations and cleanups\n\nFor more information check git-completion's project page [4].\n\nChanges since v6:\n\n * Run the zsh completion test script directly in zsh\n * Simplify the zsh zpty code for testing\n * Rebase on top of Git 2.40\n\nPast versions:\n\n * 1.4: https://lore.kernel.org/git/20220830093138.1581538-1-felipe.contreras@gmail.com/\n * 1.3.3: https://lore.kernel.org/git/20210618182518.697912-1-felipe.contreras@gmail.com/\n * 1.3.1: https://lore.kernel.org/git/20210426161458.49860-1-felipe.contreras@gmail.com/\n * 1.3: https://lore.kernel.org/git/20210101021622.798041-1-felipe.contreras@gmail.com/\n * v2: https://lore.kernel.org/git/20201110212136.870769-1-felipe.contreras@gmail.com/\n * v1: https://lore.kernel.org/git/20201104174716.783348-1-felipe.contreras@gmail.com/\n\nCheers.\n\n[1] https://lore.kernel.org/git/20230401015632.103581-1-felipe.contreras@gmail.com/\n[2] https://lore.kernel.org/git/20201223141950.GA23264@szeder.dev/\n[3] https://lore.kernel.org/git/20201104174716.783348-1-felipe.contreras@gmail.com/\n[4] https://github.com/felipec/git-completion\n\nFelipe Contreras (48):\n  test: completion add test for __git_cmd_idx\n  completion: bash: trivial cleanup\n  zsh: remove version\n  completion: bash: trivial grammar fix\n  completion: zsh: add higher-priority location\n  zsh: simplify realpath dirname idiom\n  test: completion: use global config\n  completion: fix __git_cmd_idx regression for zsh\n  completion: fix for suboptions with value\n  completion: zsh: trivial improvement\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  test: completion: add missing test\n  completion: bash: simplify config_variable_name\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\nMichael Bianco (1):\n  zsh: resolve symlink of script\n\n contrib/completion/git-completion.bash | 637 +++++++++++--------------\n contrib/completion/git-completion.zsh  | 146 +++---\n t/t9902-completion.sh                  | 167 ++++---\n t/t9904-completion-zsh.sh              |  97 ++--\n 4 files changed, 489 insertions(+), 558 deletions(-)\n\nRange-diff against v6:\n 1:  e3c5a79c51 =  1:  6d191be41c test: completion add test for __git_cmd_idx\n 2:  674c223b68 <  -:  ---------- test: add zsh completion tests\n 4:  8a6ec4348b =  2:  a59bf95ff5 completion: bash: trivial cleanup\n50:  3dd08cbdf7 =  3:  c5c105bfff zsh: remove version\n51:  88beef78a7 =  4:  0217b5641c completion: bash: trivial grammar fix\n 5:  c6e3e9c8b4 =  5:  b1548d96a2 completion: zsh: add higher-priority location\n 6:  7f34835f6e =  6:  7f2149738a zsh: resolve symlink of script\n 7:  b2c9c92c5e =  7:  8af77967ed zsh: simplify realpath dirname idiom\n -:  ---------- >  8:  aeb19ab24c test: completion: use global config\n 3:  28fd5901d7 !  9:  152eca2b34 completion: fix __git_cmd_idx regression for zsh\n    @@ contrib/completion/git-completion.zsh: __git_zsh_main ()\n      \tcur=${words[CURRENT]}\n      \tprev=${words[CURRENT-1]}\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_failure 'options with value' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_failure 'options with value' '\n      \tEOF\n      '\n      \n 8:  5496fc8ad2 <  -:  ---------- test: reset environment variables\n 9:  a70c96e720 <  -:  ---------- completion: prompt: use generic colors\n10:  3d949c4ef4 ! 10:  efe2d76308 completion: fix for suboptions with value\n    @@ contrib/completion/git-completion.zsh: __gitcomp ()\n      \t--no-*)\n      \t\tlocal c IFS=$' \\t\\n'\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - expand/narrow all negative options' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp - expand/narrow all negative options' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - expand/narrow all ne\n      \ttest_gitcomp \"--option=\" \"--option=\" <<-\\EOF &&\n      \n      \tEOF\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'git clone --config= - value' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'git clone --config= - value' '\n      \tEOF\n      '\n      \n11:  39a5e432e8 = 11:  66abcf711f completion: zsh: trivial improvement\n12:  d757c1e649 ! 12:  559f5daf27 completion: bash: do not modify COMP_WORDBREAKS\n    @@ Commit message\n     \n      ## contrib/completion/git-completion.bash ##\n     @@\n    - #     When set to \"1\" suggest all options, including options which are\n    - #     typically hidden (e.g. '--allow-empty' for 'git commit').\n    + #     case insensitively, even on systems with case sensitive file systems\n    + #     (e.g., completing tag name \"FOO\" on \"git checkout f<TAB>\").\n      \n     -case \"$COMP_WORDBREAKS\" in\n     -*:*) : great ;;\n13:  06f0430106 ! 13:  dbb1a7410e test: completion: fix currently typed words\n    @@ t/t9902-completion.sh: test_expect_success '__gitcomp - prefix' '\n      \tbranch.master.Z\n      \tbranch.maint.Z\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - option parameter' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp - option parameter' '\n      '\n      \n      test_expect_failure '__gitcomp - prefix' '\n    @@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - option parameter' '\n      \t\t\"branch.maint.\" \"me\" <<-\\EOF\n      \tbranch.maint.merge Z\n      \tbranch.maint.mergeoptions Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_failure '__gitcomp - prefix' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_failure '__gitcomp - prefix' '\n      '\n      \n      test_expect_failure '__gitcomp - suffix' '\n14:  a6f4da3602 ! 14:  2f2c240ac1 test: completion: switch __gitcomp_nl prefix test\n    @@ t/t9902-completion.sh: test_expect_success '__gitcomp_nl - trailing space' '\n      '\n      \n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp_nl - trailing space' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp_nl - trailing space' '\n      \tEOF\n      '\n      \n15:  4e11ca5f72 = 15:  c21c389bb7 test: completion: add run_func() helper\n16:  6baf13d85f = 16:  ea93b6cdec completion: bash: remove non-append functionality\n17:  2a8298ba7d = 17:  567046e66b completion: bash: get rid of _append() functions\n18:  2b6225049f = 18:  1500142923 completion: bash: get rid of any non-append code\n19:  dd5e794315 = 19:  655fac83e5 completion: zsh: fix options with arguments\n20:  b88875e756 = 20:  9a7591b665 completion: zsh: expand --git-dir file argument\n21:  045f42c461 ! 21:  58f8143817 completion: zsh: add support for general -C opts\n    @@ contrib/completion/git-completion.zsh: __git_zsh_main ()\n      \n      \t\twords=( git ${words[@]} )\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'checkout completes ref names' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'checkout completes ref names' '\n      \tEOF\n      '\n      \n22:  2c69a0d2af ! 22:  3b424c7b78 completion: zsh: fix for undefined completions\n    @@ contrib/completion/git-completion.zsh: __git_complete_command ()\n      \t\treturn 1\n      \tfi\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c\n      \tEOF\n      '\n      \n23:  40c6608ce6 ! 23:  1c6eddb71e completion: zsh: add support for general -c opts\n    @@ contrib/completion/git-completion.zsh: __git_zsh_main ()\n      \t\tlocal command=\"${words[1]}\" __git_dir __git_cmd_idx=1\n      \n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'git config - value' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'git config - value' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success 'git config - value' '\n      \ttest_completion \"git -c br\" <<-\\EOF\n      \tbranch.Z\n      \tbrowser.Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_failure 'git -c - variable name' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_failure 'git -c - variable name' '\n      \tEOF\n      '\n      \n24:  da05523a98 ! 24:  5ab47aa5e2 completion: zsh: fix extra space on foo=\n    @@ contrib/completion/git-completion.zsh: __gitcomp ()\n      \t\t\tesac\n      \t\t\tarray+=(\"$c\")\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'git -c - section' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'git -c - section' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success 'git -c - section' '\n      \ttest_completion \"git -c log.d\" <<-\\EOF\n      \tlog.date=Z\n      \tlog.decorate=Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'git clone --config= - section' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'git clone --config= - section' '\n      \tEOF\n      '\n      \n25:  92720f3b4e ! 25:  8d25832207 completion: zsh: add excluded options\n    @@ contrib/completion/git-completion.zsh: __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     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'general options' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'general options' '\n      \ttest_completion \"git --no-r\" \"--no-replace-objects\"\n      '\n      \n26:  a4b22cfc5e = 26:  1ef670094b completion: zsh: always set compset\n27:  4246b2dd11 = 27:  f2a9a5cf50 completion: factor out check in __gitcomp\n28:  549bdf25c8 = 28:  a57311923f completion: simplify equal suffix check\n29:  f2dde0eafc = 29:  48be9110f4 completion: refactor __gitcomp\n30:  98ed73aec8 = 30:  beb47c2caa completion: simplify __gitcomp\n31:  8b53745ef8 = 31:  f2e7c92b0b completion: bash: change suffix check in __gitcomp\n32:  b3ca49a9ee = 32:  ec1e4d358d completion: improve __gitcomp suffix code\n33:  24b974a7d6 ! 33:  3417863c0f test: completion: add missing test\n    @@ t/t9902-completion.sh: test_expect_success 'git config - value' '\n      \ttest_completion \"git -c br\" <<-\\EOF\n      \tbranch.Z\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'git config - value' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'git config - value' '\n      \tEOF\n      '\n      \n34:  d2a5c05e2b = 34:  4066b8e02a completion: bash: simplify config_variable_name\n35:  8c0220b07f = 35:  2efe630d2d completion: bash: improve __gitcomp description\n36:  6aaa7f3b5a ! 36:  688046c606 completion: add __gitcomp_opts\n    @@ t/t9902-completion.sh: test_expect_success '__gitcomp - ignore optional negative\n      \n      read -r -d \"\" refs <<-\\EOF\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_completion ()\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_completion ()\n      \ttest_cmp expected out_sorted\n      }\n      \n    @@ t/t9904-zsh-completion.sh: test_completion ()\n      \ttest_cmp expected out\n      }\n      \n    -@@ t/t9904-zsh-completion.sh: test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '\n      \tgit init -b main otherrepo\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success 'setup for __git_find_repo_path/_\n      \t\t--reset-author\" <<-EOF\n      \t--reuse-message=Z\n      \t--reedit-message=Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - trailing space - options' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp - trailing space - options' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - trailing space - opt\n      \t\tbranch.autosetuprebase browser.\" <<-\\EOF\n      \tbranch.Z\n      \tbranch.autosetupmerge Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - trailing space - config keys' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp - trailing space - config keys' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - trailing space - con\n      \t--abc Z\n      \t--def Z\n      \t--no-one Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp - ignore optional negative options' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp - ignore optional negative options' '\n      \tEOF\n      '\n      \n37:  d512f5ebc2 = 37:  d74e8977cd completion: bash: cleanup __gitcomp* invocations\n38:  b38b1f6e29 ! 38:  3d8e5655d0 completion: bash: shuffle __gitcomp functions\n    @@ Commit message\n     \n      ## contrib/completion/git-completion.bash ##\n     @@\n    - #     When set to \"1\" suggest all options, including options which are\n    - #     typically hidden (e.g. '--allow-empty' for 'git commit').\n    + #     case insensitively, even on systems with case sensitive file systems\n    + #     (e.g., completing tag name \"FOO\" on \"git checkout f<TAB>\").\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\n39:  86ca702ada = 39:  4164cb3b6e completion: zsh: simplify __gitcomp_direct\n40:  a5c7949d3f = 40:  866fa2ff1b completion: zsh: shuffle __gitcomp* functions\n41:  dcdc3b3626 = 41:  1243854e0d completion: zsh: fix direct quoting\n42:  1343263c53 ! 42:  a80b970a46 completion: zsh: add elements individually in __gitcomp_opts\n    @@ contrib/completion/git-completion.zsh: __gitcomp_opts ()\n      \n      __gitcomp_nl ()\n     \n    - ## t/t9904-zsh-completion.sh ##\n    -@@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp_opts - option parameter' '\n    + ## t/t9904-completion-zsh.sh ##\n    +@@ t/t9904-completion-zsh.sh: test_expect_success '__gitcomp_opts - option parameter' '\n      \tEOF\n      '\n      \n    @@ t/t9904-zsh-completion.sh: test_expect_success '__gitcomp_opts - option paramete\n      \ttest_gitcomp_opts \"branch.maint.me\" \"remote merge mergeoptions rebase\" \\\n      \t\t\"branch.maint.\" \"me\" <<-\\EOF\n      \tbranch.maint.merge Z\n    -@@ t/t9904-zsh-completion.sh: test_expect_failure '__gitcomp_opts - prefix' '\n    +@@ t/t9904-completion-zsh.sh: test_expect_failure '__gitcomp_opts - prefix' '\n      \tEOF\n      '\n      \n43:  5c3621f224 = 43:  66c429c075 completion: zsh: add __gitcompadd helper\n44:  7aaaf8f8ed = 44:  22ab31138d completion: zsh: add correct removable suffix\n45:  1ac27ad13d = 45:  290b7e753b completion: bash: simplify _get_comp_words_by_ref()\n46:  3b32bfe16b = 46:  4d0de6230c completion: bash: refactor _get_comp_words_by_ref()\n47:  32b36425ea = 47:  46b5530d25 completion: bash: cleanup _get_comp_words_by_ref()\n48:  35cbf711e8 = 48:  039a43b994 completion: bash: trivial cleanup\n49:  3a005ae3c4 = 49:  d33a04e5fd completion: bash: rename _get_comp_words_by_ref()\n-- \n2.33.0\n\n"},{"id":"474552","messageId":"20230401084626.304356-2-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 01/49] test: completion add test for __git_cmd_idx","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:38Z","receivedAt":"2023-04-01T08:46:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"When __git_func_wrap was fixed to set correctly __git_cmd_idx in\ncea232194d (completion: bash: fix late declaration of __git_cmd_idx,\n2021-06-18) no test was added, therefore we could hit the same bug in\nthe future.\n\nTo ensure that doesn't happen add a test which adds an alias for 'git\nadd' with __git_complete, and then pretend the user typed this alias.\n\nTo make sure __git_cmd_idx is correct we add the --update option to\nensure the result of __git_find_on_cmdline (which uses __git_cmd_idx) is\ncorrect. When __git_cmd_idx isn't correct __git_find_on_cmdline fails,\nand therefore the --update option isn't interpreted correctly.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex d6c0478d98..561f06b46a 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2689,4 +2689,13 @@ test_expect_success '__git_complete' '\n \ttest_must_fail __git_complete ga missing\n '\n \n+test_expect_success '__git_complete has correct __git_cmd_idx' '\n+\t__git_complete ga _git_add &&\n+\techo modified > file1 &&\n+\ttouch file3 &&\n+\t_words=(ga --update f) _cword=2 &&\n+\t__git_wrap_git_add &&\n+\ttest \"${COMPREPLY[*]}\" = \"file1\"\n+'\n+\n test_done\n-- \n2.33.0\n\n"},{"id":"474553","messageId":"20230401084626.304356-4-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 03/49] zsh: remove version","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:40Z","receivedAt":"2023-04-01T08:46:42Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Doesn't seem to be useful.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 5 -----\n 1 file changed, 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex cac6f61881..c7bc6a8f8e 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -135,11 +135,6 @@ __gitcomp_file_direct ()\n \t__gitcomp_file \"$1\" \"\"\n }\n \n-_git_zsh ()\n-{\n-\t__gitcomp \"v1.1\"\n-}\n-\n __git_complete_command ()\n {\n \temulate -L zsh\n-- \n2.33.0\n\n"},{"id":"474554","messageId":"20230401084626.304356-5-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 04/49] completion: bash: trivial grammar fix","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:41Z","receivedAt":"2023-04-01T08:46:44Z","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 | 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 45eaea57d5..cf6ff0595f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3330,7 +3330,7 @@ _git_worktree ()\n \t\t# Here we are not completing an --option, it's either the\n \t\t# path or a ref.\n \t\tcase \"$prev\" in\n-\t\t-b|-B)\t# Complete refs for branch to be created/reseted.\n+\t\t-b|-B)\t# Complete refs for branch to be created/reset.\n \t\t\t__git_complete_refs\n \t\t\t;;\n \t\t-*)\t# The previous word is an -o|--option without an\n-- \n2.33.0\n\n"},{"id":"474555","messageId":"20230401084626.304356-6-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 05/49] completion: zsh: add higher-priority location","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:42Z","receivedAt":"2023-04-01T08:46:47Z","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 c7bc6a8f8e..5f2c63236d 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.33.0\n\n"},{"id":"474556","messageId":"20230401084626.304356-7-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 06/49] zsh: resolve symlink of script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:43Z","receivedAt":"2023-04-01T08:46:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"From: Michael Bianco <iloveitaly@gmail.com>\n\nWhen using zinit the completions are symlinked to ~/.zinit/completions,\nthis causes the zsh script to not be able to find the bash script.\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 5f2c63236d..75bb44d41a 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -33,7 +33,7 @@ if [ -z \"$script\" ]; then\n \t\tbash_completion='/usr/share/bash-completion/completions/'\n \n \tlocations=(\n-\t\t\"$(dirname ${funcsourcetrace[1]%:*})\"/git-completion.bash\n+\t\t\"$(dirname $(realpath ${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-- \n2.33.0\n\n"},{"id":"474557","messageId":"20230401084626.304356-8-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 07/49] zsh: simplify realpath dirname idiom","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:44Z","receivedAt":"2023-04-01T08:46:55Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"There's a much simpler way in zsh.\n\nIt's a shame that ${0:A:h} doesn't work probably due to a bug in zsh.\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 75bb44d41a..4f22e8f85b 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -33,7 +33,7 @@ if [ -z \"$script\" ]; then\n \t\tbash_completion='/usr/share/bash-completion/completions/'\n \n \tlocations=(\n-\t\t\"$(dirname $(realpath ${funcsourcetrace[1]%:*}))\"/git-completion.bash\n+\t\t\"${${funcsourcetrace[1]%:*}:A:h}\"/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-- \n2.33.0\n\n"},{"id":"474558","messageId":"20230401084626.304356-9-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 08/49] test: completion: use global config","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:45Z","receivedAt":"2023-04-01T08:46:56Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Aliases are supposed to be global.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh     | 8 ++++----\n t/t9904-completion-zsh.sh | 6 +++---\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 561f06b46a..6c3cfe7e5a 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2233,7 +2233,7 @@ test_expect_success 'git --help completion' '\n '\n \n test_expect_success 'completion.commands removes multiple commands' '\n-\ttest_config completion.commands \"-cherry -mergetool\" &&\n+\ttest_config_global completion.commands \"-cherry -mergetool\" &&\n \tgit --list-cmds=list-mainporcelain,list-complete,config >out &&\n \t! grep -E \"^(cherry|mergetool)$\" out\n '\n@@ -2430,7 +2430,7 @@ test_expect_success \"recursive alias\" '\n '\n \n test_expect_success \"completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'\" '\n-\ttest_config alias.co \"!sh -c '\"'\"'git checkout ...'\"'\"'\" &&\n+\ttest_config_global alias.co \"!sh -c '\"'\"'git checkout ...'\"'\"'\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\n@@ -2439,7 +2439,7 @@ test_expect_success \"completion uses <cmd> completion for alias: !sh -c 'git <cm\n '\n \n test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '\n-\ttest_config alias.co \"!f () { VAR=val git checkout ... ; } f\" &&\n+\ttest_config_global alias.co \"!f () { VAR=val git checkout ... ; } f\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\n@@ -2448,7 +2448,7 @@ test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val\n '\n \n test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '\n-\ttest_config alias.co \"!f() { : git checkout ; if ... } f\" &&\n+\ttest_config_global alias.co \"!f() { : git checkout ; if ... } f\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 65bdaa011e..cb123261ab 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1008,7 +1008,7 @@ test_expect_success \"recursive alias\" '\n '\n \n test_expect_success \"completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'\" '\n-\ttest_config alias.co \"!sh -c '\"'\"'git checkout ...'\"'\"'\" &&\n+\ttest_config_global alias.co \"!sh -c '\"'\"'git checkout ...'\"'\"'\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\n@@ -1017,7 +1017,7 @@ test_expect_success \"completion uses <cmd> completion for alias: !sh -c 'git <cm\n '\n \n test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '\n-\ttest_config alias.co \"!f () { VAR=val git checkout ... ; } f\" &&\n+\ttest_config_global alias.co \"!f () { VAR=val git checkout ... ; } f\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\n@@ -1026,7 +1026,7 @@ test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val\n '\n \n test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '\n-\ttest_config alias.co \"!f() { : git checkout ; if ... } f\" &&\n+\ttest_config_global alias.co \"!f() { : git checkout ; if ... } f\" &&\n \ttest_completion \"git co m\" <<-\\EOF\n \tmain Z\n \tmybranch Z\n-- \n2.33.0\n\n"},{"id":"474559","messageId":"20230401084626.304356-10-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 09/49] completion: fix __git_cmd_idx regression for zsh","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:46Z","receivedAt":"2023-04-01T08:47:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"The commit 59d85a2a05 (git-completion.bash: use $__git_cmd_idx in more\nplaces, 2021-04-22) caused a regression when using __git_complete and a\ncommand relies on __git_cmd_idx. This was fixed in cea232194d\n(completion: bash: fix late declaration of __git_cmd_idx, 2021-06-18)\nbut only for bash.\n\nWe need the function wrapper (__git_func_wrap in bash and _git in zsh)\nto define __git_cmd_idx.\n\nOtherwise the equivalent of __git_complete in zsh fails:\n\n  compdef _git ga=git_add\n  ga <tab>\n  ga __git_find_on_cmdline:[:14: unknown condition: -lt\n\nReported-by: Harrison McCullough <mccullough.harrison@gmail.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 2 +-\n t/t9904-completion-zsh.sh             | 6 ++++++\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 4f22e8f85b..d11f4765b6 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -267,7 +267,7 @@ __git_zsh_main ()\n _git ()\n {\n \tlocal _ret=1\n-\tlocal cur cword prev\n+\tlocal cur cword prev __git_cmd_idx=0\n \n \tcur=${words[CURRENT]}\n \tprev=${words[CURRENT-1]}\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex cb123261ab..b7e4029bf9 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1140,4 +1140,10 @@ test_expect_failure 'options with value' '\n \tEOF\n '\n \n+test_expect_success 'main sets correct __git_cmd_idx' '\n+\techo modified > file1 &&\n+\ttouch file3 &&\n+\ttest_completion \"compdef _git ga=git_add${LF}ga --update f\" \"file1\"\n+'\n+\n test_done\n-- \n2.33.0\n\n"},{"id":"474560","messageId":"20230401084626.304356-11-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 10/49] completion: fix for suboptions with value","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:47Z","receivedAt":"2023-04-01T08:47:10Z","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.zsh | 2 +-\n t/t9904-completion-zsh.sh             | 4 ++--\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex d11f4765b6..13809f7894 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -56,7 +56,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/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex b7e4029bf9..994d57a67f 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -176,7 +176,7 @@ test_expect_success '__gitcomp - expand/narrow all negative options' '\n \tEOF\n '\n \n-test_expect_failure '__gitcomp - equal skip' '\n+test_expect_success '__gitcomp - equal skip' '\n \ttest_gitcomp \"--option=\" \"--option=\" <<-\\EOF &&\n \n \tEOF\n@@ -1134,7 +1134,7 @@ test_expect_success 'git clone --config= - value' '\n \tEOF\n '\n \n-test_expect_failure 'options with value' '\n+test_expect_success 'options with value' '\n \ttest_completion \"git merge -X diff-algorithm=\" <<-\\EOF\n \n \tEOF\n-- \n2.33.0\n\n"},{"id":"474561","messageId":"20230401084626.304356-12-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 11/49] completion: zsh: trivial improvement","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:48Z","receivedAt":"2023-04-01T08:47:21Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"$words has basically all the words we need, except the first one: git.\n\nLets simply add that instead of passing the original, which contains\noptions we don't want to pass downstream (like -c and -C).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 13809f7894..790879e319 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -215,9 +215,6 @@ __git_zsh_main ()\n {\n \tlocal curcontext=\"$curcontext\" state state_descr line\n \ttypeset -A opt_args\n-\tlocal -a orig_words\n-\n-\torig_words=( ${words[@]} )\n \n \t_arguments -C \\\n \t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n@@ -257,7 +254,7 @@ __git_zsh_main ()\n \n \t\t(( $+opt_args[--help] )) && command='help'\n \n-\t\twords=( ${orig_words[@]} )\n+\t\twords=( git ${words[@]} )\n \n \t\t__git_zsh_bash_func $command\n \t\t;;\n-- \n2.33.0\n\n"},{"id":"474562","messageId":"20230401084626.304356-13-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 12/49] completion: bash: do not modify COMP_WORDBREAKS","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:49Z","receivedAt":"2023-04-01T08:47: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 cf6ff0595f..fd2a43de38 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -65,11 +65,6 @@\n #     case insensitively, even on systems with case sensitive file systems\n #     (e.g., completing tag name \"FOO\" on \"git checkout f<TAB>\").\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 790879e319..186c49195b 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -46,6 +46,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.33.0\n\n"},{"id":"474563","messageId":"20230401084626.304356-14-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 13/49] test: completion: fix currently typed words","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:50Z","receivedAt":"2023-04-01T08:47:30Z","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 changes.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh     | 4 ++--\n t/t9904-completion-zsh.sh | 4 ++--\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 6c3cfe7e5a..bfd8570885 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\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 994d57a67f..9221539296 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -125,7 +125,7 @@ test_expect_success '__gitcomp - option parameter' '\n '\n \n test_expect_failure '__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@@ -133,7 +133,7 @@ test_expect_failure '__gitcomp - prefix' '\n '\n \n test_expect_failure '__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.33.0\n\n"},{"id":"474564","messageId":"20230401084626.304356-15-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 14/49] test: completion: switch __gitcomp_nl prefix test","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:51Z","receivedAt":"2023-04-01T08:47:32Z","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\nIn bash there are no functional changes, but in zsh this makes the test\npass.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh     | 6 +++---\n t/t9904-completion-zsh.sh | 8 ++++----\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex bfd8570885..9d973f21ce 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 \ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 9221539296..ee8cbe3320 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -199,10 +199,10 @@ test_expect_success '__gitcomp_nl - trailing space' '\n \tEOF\n '\n \n-test_expect_failure '__gitcomp_nl - prefix' '\n-\ttest_gitcomp_nl \"--fixup=m\" \"$refs\" \"--fixup=\" \"m\" <<-EOF\n-\t--fixup=main Z\n-\t--fixup=maint Z\n+test_expect_success '__gitcomp_nl - prefix' '\n+\ttest_gitcomp_nl \"branch.m\" \"$refs\" \"branch.\" \"m\" <<-EOF\n+\tbranch.main Z\n+\tbranch.maint Z\n \tEOF\n '\n \n-- \n2.33.0\n\n"},{"id":"474565","messageId":"20230401084626.304356-16-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 15/49] test: completion: add run_func() helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:52Z","receivedAt":"2023-04-01T08:47:39Z","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 9d973f21ce..a2f2f9dc09 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@@ -1931,8 +1924,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@@ -2487,8 +2479,7 @@ do\n \t\t\twords=(git push '$flag' other ma) &&\n \t\t\tcword=${#words[@]} cur=${words[cword-1]} &&\n \t\t\t__git_cmd_idx=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@@ -2501,8 +2492,7 @@ do\n \t\t\twords=(git push other '$flag' ma) &&\n \t\t\tcword=${#words[@]} cur=${words[cword-1]} &&\n \t\t\t__git_cmd_idx=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.33.0\n\n"},{"id":"474566","messageId":"20230401084626.304356-17-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 16/49] completion: bash: remove non-append functionality","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:53Z","receivedAt":"2023-04-01T08:47:48Z","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\nNo 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 fd2a43de38..7554c3aeb3 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -318,7 +318,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@@ -470,7 +470,6 @@ __gitcomp_nl_append ()\n #    appended.\n __gitcomp_nl ()\n {\n-\tCOMPREPLY=()\n \t__gitcomp_nl_append \"$@\"\n }\n \n-- \n2.33.0\n\n"},{"id":"474567","messageId":"20230401084626.304356-18-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 17/49] completion: bash: get rid of _append() functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:54Z","receivedAt":"2023-04-01T08:47:55Z","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 7554c3aeb3..3c8f907d45 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -307,8 +307,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@@ -321,19 +320,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@@ -451,16 +437,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@@ -470,7 +448,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@@ -871,7 +850,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@@ -2670,7 +2649,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@@ -2720,7 +2699,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 186c49195b..b31c9894e4 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -122,16 +122,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.33.0\n\n"},{"id":"474568","messageId":"20230401084626.304356-19-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 18/49] completion: bash: get rid of any non-append code","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:55Z","receivedAt":"2023-04-01T08:47:56Z","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 3c8f907d45..98eb7c9604 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -320,7 +320,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@@ -330,12 +330,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@@ -449,7 +443,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@@ -462,7 +456,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.33.0\n\n"},{"id":"474569","messageId":"20230401084626.304356-20-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 19/49] completion: zsh: fix options with arguments","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:56Z","receivedAt":"2023-04-01T08:47:58Z","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 b31c9894e4..0619d05d34 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -210,15 +210,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.33.0\n\n"},{"id":"474570","messageId":"20230401084626.304356-21-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 20/49] completion: zsh: expand --git-dir file argument","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:57Z","receivedAt":"2023-04-01T08:47:59Z","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 0619d05d34..b49bce51ac 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -240,7 +240,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.33.0\n\n"},{"id":"474571","messageId":"20230401084626.304356-22-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 21/49] completion: zsh: add support for general -C opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:58Z","receivedAt":"2023-04-01T08:48:08Z","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 | 6 ++++++\n t/t9904-completion-zsh.sh             | 2 +-\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex b49bce51ac..9e821eab9a 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -206,6 +206,7 @@ __git_zsh_main ()\n {\n \tlocal curcontext=\"$curcontext\" state state_descr line\n \ttypeset -A opt_args\n+\tlocal -a __git_C_args\n \n \t_arguments -C \\\n \t\t'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \\\n@@ -221,6 +222,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@@ -243,6 +245,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=( git ${words[@]} )\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex ee8cbe3320..27f5b42318 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -863,7 +863,7 @@ test_expect_success 'checkout completes ref names' '\n \tEOF\n '\n \n-test_expect_failure 'git -C <path> checkout uses the right repo' '\n+test_expect_success 'git -C <path> checkout uses the right repo' '\n \ttest_completion \"git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b\" <<-\\EOF\n \tbranch-in-other Z\n \tEOF\n-- \n2.33.0\n\n"},{"id":"474572","messageId":"20230401084626.304356-23-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 22/49] completion: zsh: fix for undefined completions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:45:59Z","receivedAt":"2023-04-01T08:48:10Z","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 t/t9904-completion-zsh.sh             | 2 +-\n 2 files changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 9e821eab9a..88157b0867 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -136,6 +136,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\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 27f5b42318..472b02d3e6 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1034,7 +1034,7 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c\n \tEOF\n '\n \n-test_expect_failure 'completion without explicit _git_xxx function' '\n+test_expect_success 'completion without explicit _git_xxx function' '\n \ttest_completion \"git version --\" <<-\\EOF\n \t--build-options Z\n \t--no-build-options Z\n-- \n2.33.0\n\n"},{"id":"474573","messageId":"20230401084626.304356-24-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 23/49] completion: zsh: add support for general -c opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:00Z","receivedAt":"2023-04-01T08:48:17Z","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 t/t9904-completion-zsh.sh             | 4 ++--\n 2 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 88157b0867..a7a5efbd13 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -226,6 +226,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@@ -239,6 +240,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 __git_cmd_idx=1\n \ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 472b02d3e6..1b18bf5363 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1090,7 +1090,7 @@ test_expect_success 'git config - value' '\n \tEOF\n '\n \n-test_expect_failure 'git -c - section' '\n+test_expect_success 'git -c - section' '\n \ttest_completion \"git -c br\" <<-\\EOF\n \tbranch.Z\n \tbrowser.Z\n@@ -1105,7 +1105,7 @@ test_expect_failure 'git -c - variable name' '\n \tEOF\n '\n \n-test_expect_failure 'git -c - value' '\n+test_expect_success 'git -c - value' '\n \ttest_completion \"git -c color.pager=\" <<-\\EOF\n \tfalse Z\n \ttrue Z\n-- \n2.33.0\n\n"},{"id":"474574","messageId":"20230401084626.304356-25-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 24/49] completion: zsh: fix extra space on foo=","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:01Z","receivedAt":"2023-04-01T08:48:19Z","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 t/t9904-completion-zsh.sh             | 4 ++--\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex a7a5efbd13..038ab30869 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -87,7 +87,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\")\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 1b18bf5363..4355552434 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1097,7 +1097,7 @@ test_expect_success 'git -c - section' '\n \tEOF\n '\n \n-test_expect_failure 'git -c - variable name' '\n+test_expect_success 'git -c - variable name' '\n \ttest_completion \"git -c log.d\" <<-\\EOF\n \tlog.date=Z\n \tlog.decorate=Z\n@@ -1119,7 +1119,7 @@ test_expect_success 'git clone --config= - section' '\n \tEOF\n '\n \n-test_expect_failure 'git clone --config= - variable name' '\n+test_expect_success 'git clone --config= - variable name' '\n \ttest_completion \"git clone --config=log.d\" <<-\\EOF\n \tlog.date=Z\n \tlog.decorate=Z\n-- \n2.33.0\n\n"},{"id":"474575","messageId":"20230401084626.304356-26-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 25/49] completion: zsh: add excluded options","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:02Z","receivedAt":"2023-04-01T08:48:20Z","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 t/t9904-completion-zsh.sh             |  2 +-\n 2 files changed, 10 insertions(+), 9 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 038ab30869..0c8fdb584f 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -212,15 +212,16 @@ __git_zsh_main ()\n \tlocal -a __git_C_args\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]' \\\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 4355552434..c0be5573ee 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -821,7 +821,7 @@ test_expect_success 'general options' '\n \ttest_completion \"git --no-r\" \"--no-replace-objects\"\n '\n \n-test_expect_failure 'general options plus command' '\n+test_expect_success 'general options plus command' '\n \ttest_completion \"git --version check\" \"\" &&\n \ttest_completion \"git --paginate check\" \"checkout\" &&\n \ttest_completion \"git --git-dir=foo check\" \"checkout\" &&\n-- \n2.33.0\n\n"},{"id":"474576","messageId":"20230401084626.304356-27-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 26/49] completion: zsh: always set compset","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:03Z","receivedAt":"2023-04-01T08:48:28Z","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 0c8fdb584f..0b6289af0a 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -73,7 +73,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@@ -92,7 +91,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@@ -102,7 +100,6 @@ __gitcomp_direct ()\n {\n \temulate -L zsh\n \n-\tcompset -P '*[=:]'\n \tcompadd -Q -S '' -- ${(f)1} && _ret=0\n }\n \n@@ -110,7 +107,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@@ -118,7 +114,6 @@ __gitcomp_file ()\n {\n \temulate -L zsh\n \n-\tcompset -P '*[=:]'\n \tcompadd -f -p \"${2-}\" -- ${(f)1} && _ret=0\n }\n \n@@ -131,6 +126,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.33.0\n\n"},{"id":"474577","messageId":"20230401084626.304356-28-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 27/49] completion: factor out check in __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:04Z","receivedAt":"2023-04-01T08:48:29Z","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 98eb7c9604..e07d5054cb 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -341,9 +341,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 0b6289af0a..202f66a4f7 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -56,9 +56,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.33.0\n\n"},{"id":"474578","messageId":"20230401084626.304356-29-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 28/49] completion: simplify equal suffix check","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:05Z","receivedAt":"2023-04-01T08:48:31Z","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 e07d5054cb..187350dbfc 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -355,7 +355,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 202f66a4f7..c9520589db 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -68,7 +68,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.33.0\n\n"},{"id":"474579","messageId":"20230401084626.304356-30-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 29/49] completion: refactor __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:06Z","receivedAt":"2023-04-01T08:48:32Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"We have two 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 187350dbfc..9de394b223 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -345,44 +345,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+\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-\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-\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-\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 c9520589db..029ca23e50 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -58,42 +58,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.33.0\n\n"},{"id":"474580","messageId":"20230401084626.304356-31-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 30/49] completion: simplify __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:07Z","receivedAt":"2023-04-01T08:48:34Z","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 9de394b223..502a1657a1 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -352,9 +352,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 029ca23e50..04265bcb22 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -63,7 +63,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.33.0\n\n"},{"id":"474581","messageId":"20230401084626.304356-32-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 31/49] completion: bash: change suffix check in __gitcomp","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:08Z","receivedAt":"2023-04-01T08:48:35Z","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 502a1657a1..63a3235544 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -357,8 +357,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.33.0\n\n"},{"id":"474582","messageId":"20230401084626.304356-33-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 32/49] completion: improve __gitcomp suffix code","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:09Z","receivedAt":"2023-04-01T08:48:52Z","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\nThe only exception is __git_complete_config_variable_name, so make sure\nwe pass the correct suffix.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash | 19 +++++++++++--------\n contrib/completion/git-completion.zsh  | 18 +++++++++++-------\n 2 files changed, 22 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 63a3235544..eb7be6aa6c 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -345,7 +345,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@@ -358,12 +358,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 }\n@@ -2606,7 +2609,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\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 04265bcb22..290fd0252d 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -58,7 +58,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@@ -66,12 +66,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.33.0\n\n"},{"id":"474583","messageId":"20230401084626.304356-34-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 33/49] test: completion: add missing test","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:10Z","receivedAt":"2023-04-01T08:49:02Z","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\nNow it should work even in bash < 4.0.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n t/t9902-completion.sh     | 7 +++++++\n t/t9904-completion-zsh.sh | 7 +++++++\n 2 files changed, 14 insertions(+)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex a2f2f9dc09..c33543191f 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2533,6 +2533,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\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex c0be5573ee..1c694bec0d 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -1090,6 +1090,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.33.0\n\n"},{"id":"474584","messageId":"20230401084626.304356-35-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 34/49] completion: bash: simplify config_variable_name","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:11Z","receivedAt":"2023-04-01T08:49:04Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Now sfx is never null.\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 eb7be6aa6c..2974604e99 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2631,7 +2631,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@@ -2665,7 +2665,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@@ -2681,7 +2681,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.33.0\n\n"},{"id":"474585","messageId":"20230401084626.304356-36-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 35/49] completion: bash: improve __gitcomp description","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:12Z","receivedAt":"2023-04-01T08:49:06Z","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 2974604e99..6633b866fb 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -330,8 +330,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.33.0\n\n"},{"id":"474586","messageId":"20230401084626.304356-37-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 36/49] completion: add __gitcomp_opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:13Z","receivedAt":"2023-04-01T08:49:08Z","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 | 94 +++++++++++++++-----------\n contrib/completion/git-completion.zsh  |  8 +++\n t/t9902-completion.sh                  | 58 ++++++++--------\n t/t9904-completion-zsh.sh              | 54 +++++++--------\n 4 files changed, 117 insertions(+), 97 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6633b866fb..ba225e999a 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -330,13 +330,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@@ -380,7 +392,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@@ -415,7 +427,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@@ -1066,7 +1078,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@@ -1076,7 +1088,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@@ -1318,7 +1330,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@@ -1578,7 +1590,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@@ -1737,7 +1749,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@@ -2031,7 +2043,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@@ -2094,7 +2106,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@@ -2242,7 +2254,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@@ -2259,11 +2271,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@@ -2877,7 +2889,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@@ -2909,7 +2921,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@@ -2947,7 +2959,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@@ -3073,7 +3085,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@@ -3084,29 +3096,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@@ -3147,64 +3159,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@@ -3444,7 +3456,7 @@ __git_main ()\n \t\tesac\n \t\tcase \"$cur\" in\n \t\t--*)\n-\t\t\t__gitcomp \"\n+\t\t\t__gitcomp_opts \"\n \t\t\t--paginate\n \t\t\t--no-pager\n \t\t\t--git-dir=\n@@ -3501,7 +3513,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 290fd0252d..83d2bc99a1 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -54,6 +54,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 c33543191f..b4ed415245 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\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 1c694bec0d..79c1368769 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -56,16 +56,16 @@ 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 \tsed -e 's/Z$//' >expected &&\n \tlocal cur=\"$1\" &&\n \tshift &&\n-\trun_completion \"git func __gitcomp $(printf \"%q \" \"$@\") $cur\" &&\n+\trun_completion \"git func __gitcomp_opts $(printf \"%q \" \"$@\") $cur\" &&\n \ttest_cmp expected out\n }\n \n@@ -97,8 +97,8 @@ test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '\n \tgit init -b main otherrepo\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@@ -106,8 +106,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@@ -116,32 +116,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_failure '__gitcomp - prefix' '\n-\ttest_gitcomp \"branch.maint.me\" \"remote merge mergeoptions rebase\" \\\n+test_expect_failure '__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_failure '__gitcomp - suffix' '\n-\ttest_gitcomp \"branch.ma\" \"master maint next seen\" \"branch.\" \\\n+test_expect_failure '__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@@ -149,38 +149,38 @@ 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-- \n2.33.0\n\n"},{"id":"474587","messageId":"20230401084626.304356-38-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 37/49] completion: bash: cleanup __gitcomp* invocations","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:14Z","receivedAt":"2023-04-01T08:49:14Z","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 ba225e999a..bc6f83adce 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1394,7 +1394,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@@ -1808,9 +1808,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@@ -2316,7 +2314,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@@ -2340,9 +2338,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@@ -2642,7 +2638,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@@ -2692,7 +2688,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@@ -2707,7 +2703,7 @@ __git_complete_config_variable_name ()\n \t\t;;\n \t*)\n \t\t__git_compute_config_sections\n-\t\t__gitcomp \"$__git_config_sections\" \"\" \"$cur_\" \".\"\n+\t\t__gitcomp_nl \"$__git_config_sections\" \"\" \"$cur_\" \".\"\n \t\t;;\n \tesac\n }\n@@ -2801,7 +2797,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@@ -3484,7 +3480,7 @@ __git_main ()\n \t\t\t\tthen\n \t\t\t\t\tlist_cmds=builtins,$list_cmds\n \t\t\t\tfi\n-\t\t\t\t__gitcomp \"$(__git --list-cmds=$list_cmds)\"\n+\t\t\t\t__gitcomp_nl \"$(__git --list-cmds=$list_cmds)\"\n \t\t\tfi\n \t\t\t;;\n \t\tesac\n-- \n2.33.0\n\n"},{"id":"474588","messageId":"20230401084626.304356-39-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 38/49] completion: bash: shuffle __gitcomp functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:15Z","receivedAt":"2023-04-01T08:49:15Z","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 bc6f83adce..3f48b61cbe 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -65,6 +65,145 @@\n #     case insensitively, even on systems with case sensitive file systems\n #     (e.g., completing tag name \"FOO\" on \"git checkout f<TAB>\").\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@@ -307,81 +446,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@@ -430,62 +494,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.33.0\n\n"},{"id":"474589","messageId":"20230401084626.304356-40-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 39/49] completion: zsh: simplify __gitcomp_direct","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:16Z","receivedAt":"2023-04-01T08:49:16Z","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 83d2bc99a1..170f3d7f5e 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -90,9 +90,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.33.0\n\n"},{"id":"474590","messageId":"20230401084626.304356-41-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 40/49] completion: zsh: shuffle __gitcomp* functions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:17Z","receivedAt":"2023-04-01T08:49:24Z","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 170f3d7f5e..dc04c5b703 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -88,11 +88,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@@ -107,6 +102,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.33.0\n\n"},{"id":"474591","messageId":"20230401084626.304356-42-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 41/49] completion: zsh: fix direct quoting","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:18Z","receivedAt":"2023-04-01T08:49:29Z","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 dc04c5b703..e2a7f55539 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -55,7 +55,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@@ -85,14 +85,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.33.0\n\n"},{"id":"474592","messageId":"20230401084626.304356-43-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 42/49] completion: zsh: add elements individually in __gitcomp_opts","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:19Z","receivedAt":"2023-04-01T08:49:30Z","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\nAdditionally two tests now pass because we are not using an array\nanymore.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh | 6 ++----\n t/t9904-completion-zsh.sh             | 4 ++--\n 2 files changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex e2a7f55539..ba7b0a7dbc 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -67,11 +67,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@@ -83,9 +82,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 ()\ndiff --git a/t/t9904-completion-zsh.sh b/t/t9904-completion-zsh.sh\nindex 79c1368769..24fb2dda00 100755\n--- a/t/t9904-completion-zsh.sh\n+++ b/t/t9904-completion-zsh.sh\n@@ -124,7 +124,7 @@ test_expect_success '__gitcomp_opts - option parameter' '\n \tEOF\n '\n \n-test_expect_failure '__gitcomp_opts - prefix' '\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@@ -132,7 +132,7 @@ test_expect_failure '__gitcomp_opts - prefix' '\n \tEOF\n '\n \n-test_expect_failure '__gitcomp_opts - suffix' '\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-- \n2.33.0\n\n"},{"id":"474593","messageId":"20230401084626.304356-44-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 43/49] completion: zsh: add __gitcompadd helper","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:20Z","receivedAt":"2023-04-01T08:49:38Z","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 ba7b0a7dbc..522b59cf5b 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -50,12 +50,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@@ -70,7 +74,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@@ -82,7 +86,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.33.0\n\n"},{"id":"474594","messageId":"20230401084626.304356-45-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 44/49] completion: zsh: add correct removable suffix","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:21Z","receivedAt":"2023-04-01T08:49:40Z","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 522b59cf5b..31bf88c1c5 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -52,7 +52,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@@ -80,7 +80,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.33.0\n\n"},{"id":"474595","messageId":"20230401084626.304356-46-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 45/49] completion: bash: simplify _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:22Z","receivedAt":"2023-04-01T08:49: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 3f48b61cbe..7b46ce503d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -419,30 +419,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 b4ed415245..fdc81d5d3f 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.33.0\n\n"},{"id":"474596","messageId":"20230401084626.304356-47-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 46/49] completion: bash: refactor _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:23Z","receivedAt":"2023-04-01T08:49: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 | 109 +++++++++++--------------\n 1 file changed, 47 insertions(+), 62 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 7b46ce503d..63a9409b0e 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -345,21 +345,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@@ -367,60 +357,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-{\n-\tlocal exclude i j first\n-\t# Which word separators to exclude?\n-\texclude=\"${1//[^$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-\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 \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+\tlocal exclude i j first\n+\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+\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+\tfi\n+\n \tcword=$cword_\n \tcur=${words_[cword]}\n \tprev=${words_[cword-1]}\n-- \n2.33.0\n\n"},{"id":"474597","messageId":"20230401084626.304356-48-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 47/49] completion: bash: cleanup _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:24Z","receivedAt":"2023-04-01T08:49:52Z","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 63a9409b0e..1b594f01cb 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -361,14 +361,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@@ -388,9 +387,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@@ -399,17 +398,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.33.0\n\n"},{"id":"474598","messageId":"20230401084626.304356-49-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 48/49] completion: bash: trivial cleanup","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:25Z","receivedAt":"2023-04-01T08:49:58Z","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 1b594f01cb..912e9bace0 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -366,9 +366,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@@ -403,6 +401,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.33.0\n\n"},{"id":"474599","messageId":"20230401084626.304356-50-felipe.contreras@gmail.com","threadId":"59514","inReplyTo":"20230401084626.304356-1-felipe.contreras@gmail.com","subject":"[PATCH v7 49/49] completion: bash: rename _get_comp_words_by_ref()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-04-01T08:46:26Z","receivedAt":"2023-04-01T08:50:01Z","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 | 186 ++++++++++++-------------\n t/t9902-completion.sh                  |   2 +-\n 2 files changed, 94 insertions(+), 94 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 912e9bace0..b36db3f845 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -318,98 +318,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@@ -3497,10 +3405,102 @@ 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+if ! type __git_get_comp_words_by_ref >/dev/null 2>&1; then\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+fi\n+\n __git_func_wrap ()\n {\n \tlocal cur words cword prev __git_cmd_idx=0\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 fdc81d5d3f..18f88133de 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.33.0\n\n"}]}