remote: force completing --mirror= instead of --mirror
"git remote --mirror" is a special case. Technically it is possible to specify --mirror without any argument. But we will get a "dangerous, deprecated!" warning in that case. This new parse-opt flag allows --git-completion-helper to always complete --mirror=, ignoring the dangerous use case. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 9, 2018 at 18:02 UTC
ebc4a04e8437e704e40a1d35aea030dc03ec8e56
3 files changed
+8
-2
builtin/remote.c
+1
-1
@@ -168,7 +168,7 @@ static int add(int argc, const char **argv)
168
OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
169
{ OPTION_CALLBACK, 0, "mirror", &mirror, N_("push|fetch"),
170
N_("set up remote as a mirror to push to or fetch from"),
171
- PARSE_OPT_OPTARG, parse_mirror_opt },
171
+ PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt },
172
OPT_END()
173
};
174
parse-options.c
+2
@@ -459,6 +459,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
459
default:
460
break;
461
}
462
+ if (opts->flags & PARSE_OPT_COMP_ARG)
463
+ suffix = "=";
464
printf(" --%s%s", opts->long_name, suffix);
465
}
466
fputc('\n', stdout);
parse-options.h
+5
-1
@@ -39,7 +39,8 @@ enum parse_opt_option_flags {
39
PARSE_OPT_NODASH = 32,
40
PARSE_OPT_LITERAL_ARGHELP = 64,
41
PARSE_OPT_SHELL_EVAL = 256,
42
- PARSE_OPT_NOCOMPLETE = 512
42
+ PARSE_OPT_NOCOMPLETE = 512,
43
+ PARSE_OPT_COMP_ARG = 1024
44
};
45
46
struct option;
@@ -92,6 +93,9 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
93
* Useful for options with multiple parameters.
94
* PARSE_OPT_NOCOMPLETE: by default all visible options are completable
95
* by git-completion.bash. This option suppresses that.
96
+ * PARSE_OPT_COMP_ARG: this option forces to git-completion.bash to
97
+ * complete an option as --name= not --name even if
98
+ * the option takes optional argument.
99
*
100
* `callback`::
101
* pointer to the callback to use for OPTION_CALLBACK or