{"thread":{"id":"54071","subject":"[RFC PATCH 0/2] Support enabling bash completion of all options","startedAt":"2020-08-19T17:51:08Z","lastAt":"2020-08-19T23:06:28Z","messageCount":9,"participants":["Ryan Zoeller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"404047","messageId":"20200819175047.692962-1-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":null,"subject":"[RFC PATCH 0/2] Support enabling bash completion of all options","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T17:50:58Z","receivedAt":"2020-08-19T17:51:08Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"This series adds --git-completion-helper-all, which behaves similarly to\n--git-completion-helper but includes options which are typically hidden.\nAn environment variable GIT_COMPLETION_SHOW_ALL is used to opt-in to\nthis behavior.\n\nI often prototype automated tooling around git by running commands locally\nuntil I'm satisfied with the behavior, then migrating them into a script.\nHaving bash completion for some of the more obscure options is useful.\n\nI wasn't sure how to add automated tests around this without making the\ntests overly brittle (e.g. depending on a verbatim list of options), so\nI welcome ideas and feedback.\n\n-Ryan\n\nRyan Zoeller (2):\n  parse-options: add --git-completion-helper-all\n  completion: add GIT_COMPLETION_SHOW_ALL env var\n\n contrib/completion/git-completion.bash | 14 +++++++++++++-\n parse-options.c                        | 18 ++++++++++++------\n 2 files changed, 25 insertions(+), 7 deletions(-)\n\n-- \n2.28.0.260.g5fadab5a9c\n\n\n"},{"id":"404048","messageId":"20200819175047.692962-2-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":"20200819175047.692962-1-rtzoeller@rtzoeller.com","subject":"[RFC PATCH 1/2] parse-options: add --git-completion-helper-all","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T17:51:08Z","receivedAt":"2020-08-19T17:51:13Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"--git-completion-helper excludes hidden options, such as --allow-empty\nfor git commit. This is typically helpful, but occasionally we want\nauto-completion for obscure flags. --git-completion-helper-all returns\nall options, even if they are marked as hidden or nocomplete.\n\nSigned-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n---\n parse-options.c | 18 ++++++++++++------\n 1 file changed, 12 insertions(+), 6 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex c57618d537..cc7239e1c6 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n \n \t\tif (!opts->long_name)\n \t\t\tcontinue;\n-\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n-\t\t\tcontinue;\n+\t\t/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,\n+\t\t * we expect the caller to handle these appropriately.\n+\t\t */\n \t\tif (opts->flags & PARSE_OPT_NONEG)\n \t\t\tcontinue;\n \n@@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n \t}\n }\n \n-static int show_gitcomp(const struct option *opts)\n+static int show_gitcomp(const struct option *opts, int show_all)\n {\n \tconst struct option *original_opts = opts;\n \tint nr_noopts = 0;\n@@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)\n \n \t\tif (!opts->long_name)\n \t\t\tcontinue;\n-\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n+\t\tif (!show_all &&\n+\t\t\t(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))\n \t\t\tcontinue;\n \n \t\tswitch (opts->type) {\n@@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\tif (internal_help && ctx->total == 1 && !strcmp(arg + 1, \"h\"))\n \t\t\tgoto show_usage;\n \n-\t\t/* lone --git-completion-helper is asked by git-completion.bash */\n+\t\t/* lone --git-completion-helper and --git-completion-helper-all\n+\t\t * are asked by git-completion.bash\n+\t\t */\n \t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper\"))\n-\t\t\treturn show_gitcomp(options);\n+\t\t\treturn show_gitcomp(options, 0);\n+\t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper-all\"))\n+\t\t\treturn show_gitcomp(options, 1);\n \n \t\tif (arg[1] != '-') {\n \t\t\tctx->opt = arg + 1;\n-- \n2.28.0.260.g5fadab5a9c\n\n\n"},{"id":"404049","messageId":"20200819175047.692962-3-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":"20200819175047.692962-1-rtzoeller@rtzoeller.com","subject":"[RFC PATCH 2/2] completion: add GIT_COMPLETION_SHOW_ALL env var","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T17:51:12Z","receivedAt":"2020-08-19T17:51:27Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"When set to 1, GIT_COMPLETION_SHOW_ALL causes --git-completion-helper-all\nto be passed instead of --git-completion-helper.\n\nSigned-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n---\n contrib/completion/git-completion.bash | 14 +++++++++++++-\n 1 file changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 700d44af5b..9147fba3d5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -39,6 +39,11 @@\n #     When set to \"1\", do not include \"DWIM\" suggestions in git-checkout\n #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n #     exists).\n+#\n+#   GIT_COMPLETION_SHOW_ALL\n+#\n+#     When set to \"1\" suggest all options, including options which are\n+#     typically hidden (e.g. '--allow-empty' for 'git commit').\n \n case \"$COMP_WORDBREAKS\" in\n *:*) : great ;;\n@@ -411,10 +416,17 @@ __gitcomp_builtin ()\n \tlocal options\n \teval \"options=\\${$var-}\"\n \n+\tlocal completion_helper\n+\tif [ \"$GIT_COMPLETION_SHOW_ALL\" = \"1\" ]; then\n+\t\tcompletion_helper=\"--git-completion-helper-all\"\n+\telse\n+\t\tcompletion_helper=\"--git-completion-helper\"\n+\tfi\n+\n \tif [ -z \"$options\" ]; then\n \t\t# leading and trailing spaces are significant to make\n \t\t# option removal work correctly.\n-\t\toptions=\" $incl $(__git ${cmd/_/ } --git-completion-helper) \" || return\n+\t\toptions=\" $incl $(__git ${cmd/_/ } $completion_helper) \" || return\n \n \t\tfor i in $excl; do\n \t\t\toptions=\"${options/ $i / }\"\n-- \n2.28.0.260.g5fadab5a9c\n\n\n"},{"id":"404061","messageId":"xmqqeeo2togj.fsf@gitster.c.googlers.com","threadId":"54071","inReplyTo":"20200819175047.692962-2-rtzoeller@rtzoeller.com","subject":"Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-19T19:39:24Z","receivedAt":"2020-08-19T19:39:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ryan Zoeller <rtzoeller@rtzoeller.com> writes:\n\n> --git-completion-helper excludes hidden options, such as --allow-empty\n> for git commit. This is typically helpful, but occasionally we want\n> auto-completion for obscure flags.\n\nHits from \"git grep -B2 OPT_NOCOMPLETE\" tells me that these are\nmostly unsafe options.  Those who accept the risk by saying\n\"complete all\" should be allowed to see them.\n\nThe same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a\nmixed bag.  Many are unsafe, some are uncommon and the rest are\ndiscouraged, or old synonym to some other option that does get\ncompleted.  I am not sure if letting them be completed is an overall\nwin or makes the output from \"git cmd --<TAB><TAB>\" too noisy.\n\n> --git-completion-helper-all returns\n> all options, even if they are marked as hidden or nocomplete.\n\nIf it is \"occasinally\", why is the removal of OPT_HIDDEN in\nshow_negated_gitcomp() unconditional?\n\n> Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n> ---\n>  parse-options.c | 18 ++++++++++++------\n>  1 file changed, 12 insertions(+), 6 deletions(-)\n>\n> diff --git a/parse-options.c b/parse-options.c\n> index c57618d537..cc7239e1c6 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n>  \n>  \t\tif (!opts->long_name)\n>  \t\t\tcontinue;\n> -\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n> -\t\t\tcontinue;\n> +\t\t/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,\n> +\t\t * we expect the caller to handle these appropriately.\n> +\t\t */\n\n\t/*\n\t * Style: our multi-line comments should begin with\n\t * slash-asterisk alone on its own line, and end with\n\t * asterisk-slash also on its own line, like this.\n\t */\n\nWe do not run around and fix existing style violations that would\nonly raise the patch noise, but we try not to introduce new\nviolators.\n\nI am not sure what the new comment says is justifiable.  The only\ncaller of show_negated_gitcomp() is in show_gitcomp() where the\nfunction looped over the options and showed the options normally,\nhonoring these two flags, but then the original list of options\nare passed to this function without filtering any option element\non the list that are marked with these bits, so \"the caller\"\napparently is not interested in handling the elements with these\nbits when making the decision to show \"--no-<option>\" form itself;\nit farms it out to show_negated_gitcomp() and expects the function\nto do \"the right thing\".  Am I misleading the code?\n\n\n>  \t\tif (opts->flags & PARSE_OPT_NONEG)\n>  \t\t\tcontinue;\n>  \n> @@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n>  \t}\n>  }\n>  \n> -static int show_gitcomp(const struct option *opts)\n> +static int show_gitcomp(const struct option *opts, int show_all)\n>  {\n>  \tconst struct option *original_opts = opts;\n>  \tint nr_noopts = 0;\n> @@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)\n>  \n>  \t\tif (!opts->long_name)\n>  \t\t\tcontinue;\n> -\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n> +\t\tif (!show_all &&\n> +\t\t\t(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))\n>  \t\t\tcontinue;\n>  \n>  \t\tswitch (opts->type) {\n> @@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n>  \t\tif (internal_help && ctx->total == 1 && !strcmp(arg + 1, \"h\"))\n>  \t\t\tgoto show_usage;\n>  \n> -\t\t/* lone --git-completion-helper is asked by git-completion.bash */\n> +\t\t/* lone --git-completion-helper and --git-completion-helper-all\n> +\t\t * are asked by git-completion.bash\n> +\t\t */\n\nDitto.\n\n>  \t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper\"))\n> -\t\t\treturn show_gitcomp(options);\n> +\t\t\treturn show_gitcomp(options, 0);\n> +\t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper-all\"))\n> +\t\t\treturn show_gitcomp(options, 1);\n\nThis is not your fault, but the micro-optimization to avoid\ncomparison between *arg (which already is known to be \"-\") and \"-\"\nis not worth the reduced readability.  \n\n\t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper\"))\n\t\t\treturn show_gitcomp(options, 0);\n\t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper-all\"))\n\t\t\treturn show_gitcomp(options, 1);\n\nwould be much clearer for readers to know what is going on.\n\nWith an extra \"const char *rest\" variable in the same scope as\n\"const char *arg\",\n\n\t\tif (ctx->total == 1 && \n\t\t    !skip_prefix(arg, \"--git-completion-helper\", &rest) && \n\t\t    (!*rest || !strcmp(rest, \"-all\")))\n\t\t\treturn show_gitcomp(options, *rest);\n\nwould further avoid repetitions, but some folks may find it a bit\ntoo dense.  I dunno.\n\n>  \n>  \t\tif (arg[1] != '-') {\n>  \t\t\tctx->opt = arg + 1;\n"},{"id":"404065","messageId":"a51ff9bb-47df-63ce-0b7f-508e064f4e3f@rtzoeller.com","threadId":"54071","inReplyTo":"xmqqeeo2togj.fsf@gitster.c.googlers.com","subject":"Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T20:51:11Z","receivedAt":"2020-08-19T20:51:32Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"On 8/19/20 2:39 PM, Junio C Hamano wrote:\n> \n> Ryan Zoeller <rtzoeller@rtzoeller.com> writes:\n> \n>> --git-completion-helper excludes hidden options, such as --allow-empty\n>> for git commit. This is typically helpful, but occasionally we want\n>> auto-completion for obscure flags.\n> \n> Hits from \"git grep -B2 OPT_NOCOMPLETE\" tells me that these are\n> mostly unsafe options.  Those who accept the risk by saying\n> \"complete all\" should be allowed to see them.\n> \n> The same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a\n> mixed bag.  Many are unsafe, some are uncommon and the rest are\n> discouraged, or old synonym to some other option that does get\n> completed.  I am not sure if letting them be completed is an overall\n> win or makes the output from \"git cmd --<TAB><TAB>\" too noisy.\n\nIf options marked OPT_HIDDEN are considered too internal to\nmeaningfully expose, I'm happy to hide them. I defaulted to\n\"show everything\", and backing off from that is easy enough.\n\n> \n>> --git-completion-helper-all returns\n>> all options, even if they are marked as hidden or nocomplete.\n> \n> If it is \"occasinally\", why is the removal of OPT_HIDDEN in\n> show_negated_gitcomp() unconditional?\n\nIt shouldn't have been. I visually clumped the calls to it\nas being inside the for loop, and assumed they were being skipped\nover as part of the continue.\n\n> \n>> Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n>> ---\n>>   parse-options.c | 18 ++++++++++++------\n>>   1 file changed, 12 insertions(+), 6 deletions(-)\n>>\n>> diff --git a/parse-options.c b/parse-options.c\n>> index c57618d537..cc7239e1c6 100644\n>> --- a/parse-options.c\n>> +++ b/parse-options.c\n>> @@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n>>\n>>   \t\tif (!opts->long_name)\n>>   \t\t\tcontinue;\n>> -\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n>> -\t\t\tcontinue;\n>> +\t\t/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,\n>> +\t\t * we expect the caller to handle these appropriately.\n>> +\t\t */\n> \n> \t/*\n> \t * Style: our multi-line comments should begin with\n> \t * slash-asterisk alone on its own line, and end with\n> \t * asterisk-slash also on its own line, like this.\n> \t */\n> \n> We do not run around and fix existing style violations that would\n> only raise the patch noise, but we try not to introduce new\n> violators.\n\nWill fix.\n\n> \n> I am not sure what the new comment says is justifiable.  The only\n> caller of show_negated_gitcomp() is in show_gitcomp() where the\n> function looped over the options and showed the options normally,\n> honoring these two flags, but then the original list of options\n> are passed to this function without filtering any option element\n> on the list that are marked with these bits, so \"the caller\"\n> apparently is not interested in handling the elements with these\n> bits when making the decision to show \"--no-<option>\" form itself;\n> it farms it out to show_negated_gitcomp() and expects the function\n> to do \"the right thing\".  Am I misleading the code?\n> \n> \n\nYou're not misreading it; I apparently neglected to test the completion\nfor '--no-' options with '--git-completion-helper', only\n'--git-completion-helper-all'. I'll apply the same show_all logic\nto this function.\n\n>>   \t\tif (opts->flags & PARSE_OPT_NONEG)\n>>   \t\t\tcontinue;\n>>\n>> @@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n>>   \t}\n>>   }\n>>\n>> -static int show_gitcomp(const struct option *opts)\n>> +static int show_gitcomp(const struct option *opts, int show_all)\n>>   {\n>>   \tconst struct option *original_opts = opts;\n>>   \tint nr_noopts = 0;\n>> @@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)\n>>\n>>   \t\tif (!opts->long_name)\n>>   \t\t\tcontinue;\n>> -\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n>> +\t\tif (!show_all &&\n>> +\t\t\t(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))\n>>   \t\t\tcontinue;\n>>\n>>   \t\tswitch (opts->type) {\n>> @@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n>>   \t\tif (internal_help && ctx->total == 1 && !strcmp(arg + 1, \"h\"))\n>>   \t\t\tgoto show_usage;\n>>\n>> -\t\t/* lone --git-completion-helper is asked by git-completion.bash */\n>> +\t\t/* lone --git-completion-helper and --git-completion-helper-all\n>> +\t\t * are asked by git-completion.bash\n>> +\t\t */\n> \n> Ditto.\n> \n\nWill fix.\n\n>>   \t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper\"))\n>> -\t\t\treturn show_gitcomp(options);\n>> +\t\t\treturn show_gitcomp(options, 0);\n>> +\t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper-all\"))\n>> +\t\t\treturn show_gitcomp(options, 1);\n> \n> This is not your fault, but the micro-optimization to avoid\n> comparison between *arg (which already is known to be \"-\") and \"-\"\n> is not worth the reduced readability.\n> \n> \t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper\"))\n> \t\t\treturn show_gitcomp(options, 0);\n> \t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper-all\"))\n> \t\t\treturn show_gitcomp(options, 1);\n> \n> would be much clearer for readers to know what is going on.\n> \n\nI completely agree, and will clean these up.\n\n> With an extra \"const char *rest\" variable in the same scope as\n> \"const char *arg\",\n> \n> \t\tif (ctx->total == 1 &&\n> \t\t    !skip_prefix(arg, \"--git-completion-helper\", &rest) &&\n> \t\t    (!*rest || !strcmp(rest, \"-all\")))\n> \t\t\treturn show_gitcomp(options, *rest);\n> \n> would further avoid repetitions, but some folks may find it a bit\n> too dense.  I dunno.\n\nI'm inclined to be repetitive in order to keep\n'--git-completion-helper-all' intact, e.g. for grepping.\n\n> \n>>\n>>   \t\tif (arg[1] != '-') {\n>>   \t\t\tctx->opt = arg + 1;\n\n"},{"id":"404066","messageId":"xmqq5z9etkgf.fsf@gitster.c.googlers.com","threadId":"54071","inReplyTo":"a51ff9bb-47df-63ce-0b7f-508e064f4e3f@rtzoeller.com","subject":"Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-08-19T21:05:52Z","receivedAt":"2020-08-19T21:05:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ryan Zoeller <rtzoeller@rtzoeller.com> writes:\n\n> On 8/19/20 2:39 PM, Junio C Hamano wrote:\n>> \n>> Ryan Zoeller <rtzoeller@rtzoeller.com> writes:\n>> \n>>> --git-completion-helper excludes hidden options, such as --allow-empty\n>>> for git commit. This is typically helpful, but occasionally we want\n>>> auto-completion for obscure flags.\n>> \n>> Hits from \"git grep -B2 OPT_NOCOMPLETE\" tells me that these are\n>> mostly unsafe options.  Those who accept the risk by saying\n>> \"complete all\" should be allowed to see them.\n>> \n>> The same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a\n>> mixed bag.  Many are unsafe, some are uncommon and the rest are\n>> discouraged, or old synonym to some other option that does get\n>> completed.  I am not sure if letting them be completed is an overall\n>> win or makes the output from \"git cmd --<TAB><TAB>\" too noisy.\n>\n> If options marked OPT_HIDDEN are considered too internal to\n> meaningfully expose, I'm happy to hide them. I defaulted to\n> \"show everything\", and backing off from that is easy enough.\n\nI think with the current state of HIDDEN which is applied unevenly\nand for different purposes, the only sensible thing to do for the\n\"complete-all\" operation is to show them.  If we audit all uses of\nhidden and allocate different bit for the reason why they are marked\nto be hidden, it may become possible for \"complete-all\" to be more\nintelligent about them (e.g. not showing old synonyms that exist\nonly for helping muscle memory, while showing others), but before\nthat, I do not think it makes sense to hide them all.\n\n> You're not misreading it; I apparently neglected to test the completion\n> for '--no-' options with '--git-completion-helper', only\n> '--git-completion-helper-all'. I'll apply the same show_all logic\n> to this function.\n\nThat makes sense.\n\n> I'm inclined to be repetitive in order to keep\n> '--git-completion-helper-all' intact, e.g. for grepping.\n\nGood reasoning.\n\nThanks.\n"},{"id":"404074","messageId":"20200819230523.773348-1-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":"20200819175047.692962-1-rtzoeller@rtzoeller.com","subject":"[PATCH v2 0/2] Support enabling bash completion of all options","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T23:06:04Z","receivedAt":"2020-08-19T23:06:10Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"Fix style guide violations and issue with '--no-' options.\n\nRyan Zoeller (2):\n  parse-options: add --git-completion-helper-all\n  completion: add GIT_COMPLETION_SHOW_ALL env var\n\n contrib/completion/git-completion.bash | 14 +++++++++++++-\n parse-options.c                        | 26 +++++++++++++++++---------\n 2 files changed, 30 insertions(+), 10 deletions(-)\n\n-- \n2.28.0.260.g5934a15c94\n\n\n"},{"id":"404075","messageId":"20200819230523.773348-2-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":"20200819175047.692962-1-rtzoeller@rtzoeller.com","subject":"[PATCH v2 1/2] parse-options: add --git-completion-helper-all","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T23:06:08Z","receivedAt":"2020-08-19T23:06:21Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"--git-completion-helper excludes hidden options, such as --allow-empty\nfor git commit. This is typically helpful, but occasionally we want\nauto-completion for obscure flags. --git-completion-helper-all returns\nall options, even if they are marked as hidden or nocomplete.\n\nSigned-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n---\n parse-options.c | 26 +++++++++++++++++---------\n 1 file changed, 17 insertions(+), 9 deletions(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex c57618d537..f0507432ee 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -525,7 +525,8 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,\n \tparse_options_start_1(ctx, argc, argv, prefix, options, flags);\n }\n \n-static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n+static void show_negated_gitcomp(const struct option *opts, int show_all,\n+\t\t\t\t int nr_noopts)\n {\n \tint printed_dashdash = 0;\n \n@@ -535,7 +536,8 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n \n \t\tif (!opts->long_name)\n \t\t\tcontinue;\n-\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n+\t\tif (!show_all &&\n+\t\t\t(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))\n \t\t\tcontinue;\n \t\tif (opts->flags & PARSE_OPT_NONEG)\n \t\t\tcontinue;\n@@ -572,7 +574,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)\n \t}\n }\n \n-static int show_gitcomp(const struct option *opts)\n+static int show_gitcomp(const struct option *opts, int show_all)\n {\n \tconst struct option *original_opts = opts;\n \tint nr_noopts = 0;\n@@ -582,7 +584,8 @@ static int show_gitcomp(const struct option *opts)\n \n \t\tif (!opts->long_name)\n \t\t\tcontinue;\n-\t\tif (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))\n+\t\tif (!show_all &&\n+\t\t\t(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))\n \t\t\tcontinue;\n \n \t\tswitch (opts->type) {\n@@ -610,8 +613,8 @@ static int show_gitcomp(const struct option *opts)\n \t\t\tnr_noopts++;\n \t\tprintf(\" --%s%s\", opts->long_name, suffix);\n \t}\n-\tshow_negated_gitcomp(original_opts, -1);\n-\tshow_negated_gitcomp(original_opts, nr_noopts);\n+\tshow_negated_gitcomp(original_opts, show_all, -1);\n+\tshow_negated_gitcomp(original_opts, show_all, nr_noopts);\n \tfputc('\\n', stdout);\n \treturn PARSE_OPT_COMPLETE;\n }\n@@ -723,9 +726,14 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,\n \t\tif (internal_help && ctx->total == 1 && !strcmp(arg + 1, \"h\"))\n \t\t\tgoto show_usage;\n \n-\t\t/* lone --git-completion-helper is asked by git-completion.bash */\n-\t\tif (ctx->total == 1 && !strcmp(arg + 1, \"-git-completion-helper\"))\n-\t\t\treturn show_gitcomp(options);\n+\t\t/*\n+\t\t * lone --git-completion-helper and --git-completion-helper-all\n+\t\t * are asked by git-completion.bash\n+\t\t */\n+\t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper\"))\n+\t\t\treturn show_gitcomp(options, 0);\n+\t\tif (ctx->total == 1 && !strcmp(arg, \"--git-completion-helper-all\"))\n+\t\t\treturn show_gitcomp(options, 1);\n \n \t\tif (arg[1] != '-') {\n \t\t\tctx->opt = arg + 1;\n-- \n2.28.0.260.g5934a15c94\n\n\n"},{"id":"404076","messageId":"20200819230523.773348-3-rtzoeller@rtzoeller.com","threadId":"54071","inReplyTo":"20200819175047.692962-1-rtzoeller@rtzoeller.com","subject":"[PATCH v2 2/2] completion: add GIT_COMPLETION_SHOW_ALL env var","fromName":"Ryan Zoeller","fromEmail":"rtzoeller@rtzoeller.com","sentAt":"2020-08-19T23:06:13Z","receivedAt":"2020-08-19T23:06:28Z","isPatch":true,"sender":{"key":"rtzoeller@rtzoeller.com","avatar":"https://avatars.githubusercontent.com/u/573497?v=4"},"body":"When set to 1, GIT_COMPLETION_SHOW_ALL causes --git-completion-helper-all\nto be passed instead of --git-completion-helper.\n\nSigned-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>\n---\n contrib/completion/git-completion.bash | 14 +++++++++++++-\n 1 file changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 700d44af5b..9147fba3d5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -39,6 +39,11 @@\n #     When set to \"1\", do not include \"DWIM\" suggestions in git-checkout\n #     and git-switch completion (e.g., completing \"foo\" when \"origin/foo\"\n #     exists).\n+#\n+#   GIT_COMPLETION_SHOW_ALL\n+#\n+#     When set to \"1\" suggest all options, including options which are\n+#     typically hidden (e.g. '--allow-empty' for 'git commit').\n \n case \"$COMP_WORDBREAKS\" in\n *:*) : great ;;\n@@ -411,10 +416,17 @@ __gitcomp_builtin ()\n \tlocal options\n \teval \"options=\\${$var-}\"\n \n+\tlocal completion_helper\n+\tif [ \"$GIT_COMPLETION_SHOW_ALL\" = \"1\" ]; then\n+\t\tcompletion_helper=\"--git-completion-helper-all\"\n+\telse\n+\t\tcompletion_helper=\"--git-completion-helper\"\n+\tfi\n+\n \tif [ -z \"$options\" ]; then\n \t\t# leading and trailing spaces are significant to make\n \t\t# option removal work correctly.\n-\t\toptions=\" $incl $(__git ${cmd/_/ } --git-completion-helper) \" || return\n+\t\toptions=\" $incl $(__git ${cmd/_/ } $completion_helper) \" || return\n \n \t\tfor i in $excl; do\n \t\t\toptions=\"${options/ $i / }\"\n-- \n2.28.0.260.g5934a15c94\n\n\n"}]}