threads / rfc / 54071

RFC patch, 2 partsSupport enabling bash completion of all options

Subject: [RFC PATCH 0/2] Support enabling bash completion of all options

## tl;dr

9 messages between Aug 19, 2020 and Aug 19, 2020. Diffs are folded; open one to read it.

replies: 8people: 2as markdown or json

Ryan Zoeller· Aug 19, 2020, 17:50 UTC · lore

This series adds --git-completion-helper-all, which behaves similarly to --git-completion-helper but includes options which are typically hidden. An environment variable GIT_COMPLETION_SHOW_ALL is used to opt-in to this behavior.

I often prototype automated tooling around git by running commands locally until I'm satisfied with the behavior, then migrating them into a script. Having bash completion for some of the more obscure options is useful.

I wasn't sure how to add automated tests around this without making the tests overly brittle (e.g. depending on a verbatim list of options), so I welcome ideas and feedback.

-Ryan
Ryan Zoeller (2):
  parse-options: add --git-completion-helper-all
  completion: add GIT_COMPLETION_SHOW_ALL env var
 contrib/completion/git-completion.bash | 14 +++++++++++++-
 parse-options.c                        | 18 ++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)
-- 
2.28.0.260.g5fadab5a9c
Ryan Zoeller· Aug 19, 2020, 17:51 UTC · re: Ryan Zoeller · lore

[RFC PATCH 1/2] parse-options: add --git-completion-helper-all

--git-completion-helper excludes hidden options, such as --allow-empty for git commit. This is typically helpful, but occasionally we want auto-completion for obscure flags. --git-completion-helper-all returns all options, even if they are marked as hidden or nocomplete.

Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
---
 parse-options.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Show changes to parse-options.c +12 −6
diff --git a/parse-options.c b/parse-options.c
index c57618d537..cc7239e1c6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
-			continue;
+		/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,
+		 * we expect the caller to handle these appropriately.
+		 */
 		if (opts->flags & PARSE_OPT_NONEG)
 			continue;
 
@@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 	}
 }
 
-static int show_gitcomp(const struct option *opts)
+static int show_gitcomp(const struct option *opts, int show_all)
 {
 	const struct option *original_opts = opts;
 	int nr_noopts = 0;
@@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
+		if (!show_all &&
+			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
 			continue;
 
 		switch (opts->type) {
@@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h"))
 			goto show_usage;
 
-		/* lone --git-completion-helper is asked by git-completion.bash */
+		/* lone --git-completion-helper and --git-completion-helper-all
+		 * are asked by git-completion.bash
+		 */
 		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
-			return show_gitcomp(options);
+			return show_gitcomp(options, 0);
+		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper-all"))
+			return show_gitcomp(options, 1);
 
 		if (arg[1] != '-') {
 			ctx->opt = arg + 1;
-- 
2.28.0.260.g5fadab5a9c
Junio C Hamano· Aug 19, 2020, 19:39 UTC · re: Ryan Zoeller · lore

Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all

Ryan Zoeller <rtzoeller@rtzoeller.com> writes:
> --git-completion-helper excludes hidden options, such as --allow-empty
> for git commit. This is typically helpful, but occasionally we want
> auto-completion for obscure flags.

Hits from "git grep -B2 OPT_NOCOMPLETE" tells me that these are mostly unsafe options. Those who accept the risk by saying "complete all" should be allowed to see them.

The same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a mixed bag. Many are unsafe, some are uncommon and the rest are discouraged, or old synonym to some other option that does get completed. I am not sure if letting them be completed is an overall win or makes the output from "git cmd --<TAB><TAB>" too noisy.

> --git-completion-helper-all returns
> all options, even if they are marked as hidden or nocomplete.

If it is "occasinally", why is the removal of OPT_HIDDEN in show_negated_gitcomp() unconditional?

Show 18 quoted lines
> Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
> ---
>  parse-options.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index c57618d537..cc7239e1c6 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
>  
>  		if (!opts->long_name)
>  			continue;
> -		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
> -			continue;
> +		/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,
> +		 * we expect the caller to handle these appropriately.
> +		 */
	/*
	 * Style: our multi-line comments should begin with
	 * slash-asterisk alone on its own line, and end with
	 * asterisk-slash also on its own line, like this.
	 */

We do not run around and fix existing style violations that would only raise the patch noise, but we try not to introduce new violators.

I am not sure what the new comment says is justifiable. The only caller of show_negated_gitcomp() is in show_gitcomp() where the function looped over the options and showed the options normally, honoring these two flags, but then the original list of options are passed to this function without filtering any option element on the list that are marked with these bits, so "the caller" apparently is not interested in handling the elements with these bits when making the decision to show "--no-<option>" form itself; it farms it out to show_negated_gitcomp() and expects the function to do "the right thing". Am I misleading the code?

Show 30 quoted lines
>  		if (opts->flags & PARSE_OPT_NONEG)
>  			continue;
>  
> @@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
>  	}
>  }
>  
> -static int show_gitcomp(const struct option *opts)
> +static int show_gitcomp(const struct option *opts, int show_all)
>  {
>  	const struct option *original_opts = opts;
>  	int nr_noopts = 0;
> @@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)
>  
>  		if (!opts->long_name)
>  			continue;
> -		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
> +		if (!show_all &&
> +			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
>  			continue;
>  
>  		switch (opts->type) {
> @@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
>  		if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h"))
>  			goto show_usage;
>  
> -		/* lone --git-completion-helper is asked by git-completion.bash */
> +		/* lone --git-completion-helper and --git-completion-helper-all
> +		 * are asked by git-completion.bash
> +		 */
Ditto.
Show 5 quoted lines
>  		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
> -			return show_gitcomp(options);
> +			return show_gitcomp(options, 0);
> +		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper-all"))
> +			return show_gitcomp(options, 1);

This is not your fault, but the micro-optimization to avoid comparison between *arg (which already is known to be "-") and "-" is not worth the reduced readability.

		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper"))
			return show_gitcomp(options, 0);
		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper-all"))
			return show_gitcomp(options, 1);
would be much clearer for readers to know what is going on.

With an extra "const char *rest" variable in the same scope as "const char *arg",

		if (ctx->total == 1 && 
		    !skip_prefix(arg, "--git-completion-helper", &rest) && 
		    (!*rest || !strcmp(rest, "-all")))
			return show_gitcomp(options, *rest);

would further avoid repetitions, but some folks may find it a bit too dense. I dunno.

>  
>  		if (arg[1] != '-') {
>  			ctx->opt = arg + 1;
Ryan Zoeller· Aug 19, 2020, 20:51 UTC · re: Junio C Hamano · lore

Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all

On 8/19/20 2:39 PM, Junio C Hamano wrote:
Show 16 quoted lines
> 
> Ryan Zoeller <rtzoeller@rtzoeller.com> writes:
> 
>> --git-completion-helper excludes hidden options, such as --allow-empty
>> for git commit. This is typically helpful, but occasionally we want
>> auto-completion for obscure flags.
> 
> Hits from "git grep -B2 OPT_NOCOMPLETE" tells me that these are
> mostly unsafe options.  Those who accept the risk by saying
> "complete all" should be allowed to see them.
> 
> The same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a
> mixed bag.  Many are unsafe, some are uncommon and the rest are
> discouraged, or old synonym to some other option that does get
> completed.  I am not sure if letting them be completed is an overall
> win or makes the output from "git cmd --<TAB><TAB>" too noisy.

If options marked OPT_HIDDEN are considered too internal to meaningfully expose, I'm happy to hide them. I defaulted to "show everything", and backing off from that is easy enough.

Show 6 quoted lines
> 
>> --git-completion-helper-all returns
>> all options, even if they are marked as hidden or nocomplete.
> 
> If it is "occasinally", why is the removal of OPT_HIDDEN in
> show_negated_gitcomp() unconditional?

It shouldn't have been. I visually clumped the calls to it as being inside the for loop, and assumed they were being skipped over as part of the continue.

Show 29 quoted lines
> 
>> Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
>> ---
>>   parse-options.c | 18 ++++++++++++------
>>   1 file changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/parse-options.c b/parse-options.c
>> index c57618d537..cc7239e1c6 100644
>> --- a/parse-options.c
>> +++ b/parse-options.c
>> @@ -535,8 +535,9 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
>>
>>   		if (!opts->long_name)
>>   			continue;
>> -		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
>> -			continue;
>> +		/* Don't check PARSE_OPT_HIDDEN or PARSE_OPT_NOCOMPLETE,
>> +		 * we expect the caller to handle these appropriately.
>> +		 */
> 
> 	/*
> 	 * Style: our multi-line comments should begin with
> 	 * slash-asterisk alone on its own line, and end with
> 	 * asterisk-slash also on its own line, like this.
> 	 */
> 
> We do not run around and fix existing style violations that would
> only raise the patch noise, but we try not to introduce new
> violators.
Will fix.
Show 13 quoted lines
> 
> I am not sure what the new comment says is justifiable.  The only
> caller of show_negated_gitcomp() is in show_gitcomp() where the
> function looped over the options and showed the options normally,
> honoring these two flags, but then the original list of options
> are passed to this function without filtering any option element
> on the list that are marked with these bits, so "the caller"
> apparently is not interested in handling the elements with these
> bits when making the decision to show "--no-<option>" form itself;
> it farms it out to show_negated_gitcomp() and expects the function
> to do "the right thing".  Am I misleading the code?
> 
> 

You're not misreading it; I apparently neglected to test the completion for '--no-' options with '--git-completion-helper', only '--git-completion-helper-all'. I'll apply the same show_all logic to this function.

Show 33 quoted lines
>>   		if (opts->flags & PARSE_OPT_NONEG)
>>   			continue;
>>
>> @@ -572,7 +573,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
>>   	}
>>   }
>>
>> -static int show_gitcomp(const struct option *opts)
>> +static int show_gitcomp(const struct option *opts, int show_all)
>>   {
>>   	const struct option *original_opts = opts;
>>   	int nr_noopts = 0;
>> @@ -582,7 +583,8 @@ static int show_gitcomp(const struct option *opts)
>>
>>   		if (!opts->long_name)
>>   			continue;
>> -		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
>> +		if (!show_all &&
>> +			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
>>   			continue;
>>
>>   		switch (opts->type) {
>> @@ -723,9 +725,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
>>   		if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h"))
>>   			goto show_usage;
>>
>> -		/* lone --git-completion-helper is asked by git-completion.bash */
>> +		/* lone --git-completion-helper and --git-completion-helper-all
>> +		 * are asked by git-completion.bash
>> +		 */
> 
> Ditto.
> 
Will fix.
Show 17 quoted lines
>>   		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
>> -			return show_gitcomp(options);
>> +			return show_gitcomp(options, 0);
>> +		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper-all"))
>> +			return show_gitcomp(options, 1);
> 
> This is not your fault, but the micro-optimization to avoid
> comparison between *arg (which already is known to be "-") and "-"
> is not worth the reduced readability.
> 
> 		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper"))
> 			return show_gitcomp(options, 0);
> 		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper-all"))
> 			return show_gitcomp(options, 1);
> 
> would be much clearer for readers to know what is going on.
> 
I completely agree, and will clean these up.
Show 10 quoted lines
> With an extra "const char *rest" variable in the same scope as
> "const char *arg",
> 
> 		if (ctx->total == 1 &&
> 		    !skip_prefix(arg, "--git-completion-helper", &rest) &&
> 		    (!*rest || !strcmp(rest, "-all")))
> 			return show_gitcomp(options, *rest);
> 
> would further avoid repetitions, but some folks may find it a bit
> too dense.  I dunno.

I'm inclined to be repetitive in order to keep '--git-completion-helper-all' intact, e.g. for grepping.

> 
>>
>>   		if (arg[1] != '-') {
>>   			ctx->opt = arg + 1;
Junio C Hamano· Aug 19, 2020, 21:05 UTC · re: Ryan Zoeller · lore

Re: [RFC PATCH 1/2] parse-options: add --git-completion-helper-all

Ryan Zoeller <rtzoeller@rtzoeller.com> writes:
Show 21 quoted lines
> On 8/19/20 2:39 PM, Junio C Hamano wrote:
>> 
>> Ryan Zoeller <rtzoeller@rtzoeller.com> writes:
>> 
>>> --git-completion-helper excludes hidden options, such as --allow-empty
>>> for git commit. This is typically helpful, but occasionally we want
>>> auto-completion for obscure flags.
>> 
>> Hits from "git grep -B2 OPT_NOCOMPLETE" tells me that these are
>> mostly unsafe options.  Those who accept the risk by saying
>> "complete all" should be allowed to see them.
>> 
>> The same with OPT_HIDDEN (including OPT_HIDDEN_<TYPE>) gives us a
>> mixed bag.  Many are unsafe, some are uncommon and the rest are
>> discouraged, or old synonym to some other option that does get
>> completed.  I am not sure if letting them be completed is an overall
>> win or makes the output from "git cmd --<TAB><TAB>" too noisy.
>
> If options marked OPT_HIDDEN are considered too internal to
> meaningfully expose, I'm happy to hide them. I defaulted to
> "show everything", and backing off from that is easy enough.

I think with the current state of HIDDEN which is applied unevenly and for different purposes, the only sensible thing to do for the "complete-all" operation is to show them. If we audit all uses of hidden and allocate different bit for the reason why they are marked to be hidden, it may become possible for "complete-all" to be more intelligent about them (e.g. not showing old synonyms that exist only for helping muscle memory, while showing others), but before that, I do not think it makes sense to hide them all.

> You're not misreading it; I apparently neglected to test the completion
> for '--no-' options with '--git-completion-helper', only
> '--git-completion-helper-all'. I'll apply the same show_all logic
> to this function.
That makes sense.
> I'm inclined to be repetitive in order to keep
> '--git-completion-helper-all' intact, e.g. for grepping.
Good reasoning.
Thanks.
Ryan Zoeller· Aug 19, 2020, 17:51 UTC · re: Ryan Zoeller · lore

[RFC PATCH 2/2] completion: add GIT_COMPLETION_SHOW_ALL env var

When set to 1, GIT_COMPLETION_SHOW_ALL causes --git-completion-helper-all to be passed instead of --git-completion-helper.

Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
---
 contrib/completion/git-completion.bash | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +13 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 700d44af5b..9147fba3d5 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -39,6 +39,11 @@
 #     When set to "1", do not include "DWIM" suggestions in git-checkout
 #     and git-switch completion (e.g., completing "foo" when "origin/foo"
 #     exists).
+#
+#   GIT_COMPLETION_SHOW_ALL
+#
+#     When set to "1" suggest all options, including options which are
+#     typically hidden (e.g. '--allow-empty' for 'git commit').
 
 case "$COMP_WORDBREAKS" in
 *:*) : great ;;
@@ -411,10 +416,17 @@ __gitcomp_builtin ()
 	local options
 	eval "options=\${$var-}"
 
+	local completion_helper
+	if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
+		completion_helper="--git-completion-helper-all"
+	else
+		completion_helper="--git-completion-helper"
+	fi
+
 	if [ -z "$options" ]; then
 		# leading and trailing spaces are significant to make
 		# option removal work correctly.
-		options=" $incl $(__git ${cmd/_/ } --git-completion-helper) " || return
+		options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
 
 		for i in $excl; do
 			options="${options/ $i / }"
-- 
2.28.0.260.g5fadab5a9c
Ryan Zoeller· Aug 19, 2020, 23:06 UTC · re: Ryan Zoeller · lore

[PATCH v2 0/2] Support enabling bash completion of all options

Fix style guide violations and issue with '--no-' options.
Ryan Zoeller (2):
  parse-options: add --git-completion-helper-all
  completion: add GIT_COMPLETION_SHOW_ALL env var
 contrib/completion/git-completion.bash | 14 +++++++++++++-
 parse-options.c                        | 26 +++++++++++++++++---------
 2 files changed, 30 insertions(+), 10 deletions(-)
-- 
2.28.0.260.g5934a15c94
Ryan Zoeller· Aug 19, 2020, 23:06 UTC · re: Ryan Zoeller · lore

[PATCH v2 1/2] parse-options: add --git-completion-helper-all

--git-completion-helper excludes hidden options, such as --allow-empty for git commit. This is typically helpful, but occasionally we want auto-completion for obscure flags. --git-completion-helper-all returns all options, even if they are marked as hidden or nocomplete.

Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
---
 parse-options.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
Show changes to parse-options.c +17 −9
diff --git a/parse-options.c b/parse-options.c
index c57618d537..f0507432ee 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -525,7 +525,8 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
 	parse_options_start_1(ctx, argc, argv, prefix, options, flags);
 }
 
-static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
+static void show_negated_gitcomp(const struct option *opts, int show_all,
+				 int nr_noopts)
 {
 	int printed_dashdash = 0;
 
@@ -535,7 +536,8 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
+		if (!show_all &&
+			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
 			continue;
 		if (opts->flags & PARSE_OPT_NONEG)
 			continue;
@@ -572,7 +574,7 @@ static void show_negated_gitcomp(const struct option *opts, int nr_noopts)
 	}
 }
 
-static int show_gitcomp(const struct option *opts)
+static int show_gitcomp(const struct option *opts, int show_all)
 {
 	const struct option *original_opts = opts;
 	int nr_noopts = 0;
@@ -582,7 +584,8 @@ static int show_gitcomp(const struct option *opts)
 
 		if (!opts->long_name)
 			continue;
-		if (opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE))
+		if (!show_all &&
+			(opts->flags & (PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE)))
 			continue;
 
 		switch (opts->type) {
@@ -610,8 +613,8 @@ static int show_gitcomp(const struct option *opts)
 			nr_noopts++;
 		printf(" --%s%s", opts->long_name, suffix);
 	}
-	show_negated_gitcomp(original_opts, -1);
-	show_negated_gitcomp(original_opts, nr_noopts);
+	show_negated_gitcomp(original_opts, show_all, -1);
+	show_negated_gitcomp(original_opts, show_all, nr_noopts);
 	fputc('\n', stdout);
 	return PARSE_OPT_COMPLETE;
 }
@@ -723,9 +726,14 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 		if (internal_help && ctx->total == 1 && !strcmp(arg + 1, "h"))
 			goto show_usage;
 
-		/* lone --git-completion-helper is asked by git-completion.bash */
-		if (ctx->total == 1 && !strcmp(arg + 1, "-git-completion-helper"))
-			return show_gitcomp(options);
+		/*
+		 * lone --git-completion-helper and --git-completion-helper-all
+		 * are asked by git-completion.bash
+		 */
+		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper"))
+			return show_gitcomp(options, 0);
+		if (ctx->total == 1 && !strcmp(arg, "--git-completion-helper-all"))
+			return show_gitcomp(options, 1);
 
 		if (arg[1] != '-') {
 			ctx->opt = arg + 1;
-- 
2.28.0.260.g5934a15c94
Ryan Zoeller· Aug 19, 2020, 23:06 UTC · re: Ryan Zoeller · lore

[PATCH v2 2/2] completion: add GIT_COMPLETION_SHOW_ALL env var

When set to 1, GIT_COMPLETION_SHOW_ALL causes --git-completion-helper-all to be passed instead of --git-completion-helper.

Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
---
 contrib/completion/git-completion.bash | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +13 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 700d44af5b..9147fba3d5 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -39,6 +39,11 @@
 #     When set to "1", do not include "DWIM" suggestions in git-checkout
 #     and git-switch completion (e.g., completing "foo" when "origin/foo"
 #     exists).
+#
+#   GIT_COMPLETION_SHOW_ALL
+#
+#     When set to "1" suggest all options, including options which are
+#     typically hidden (e.g. '--allow-empty' for 'git commit').
 
 case "$COMP_WORDBREAKS" in
 *:*) : great ;;
@@ -411,10 +416,17 @@ __gitcomp_builtin ()
 	local options
 	eval "options=\${$var-}"
 
+	local completion_helper
+	if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
+		completion_helper="--git-completion-helper-all"
+	else
+		completion_helper="--git-completion-helper"
+	fi
+
 	if [ -z "$options" ]; then
 		# leading and trailing spaces are significant to make
 		# option removal work correctly.
-		options=" $incl $(__git ${cmd/_/ } --git-completion-helper) " || return
+		options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
 
 		for i in $excl; do
 			options="${options/ $i / }"
-- 
2.28.0.260.g5934a15c94

← back to recent threads