remote: force completing --mirror= instead of --mirror
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 9 Feb 2018 11:02:12 +0000 (18:02 +0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Feb 2018 18:24:52 +0000 (10:24 -0800)
"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>
builtin/remote.c
parse-options.c
parse-options.h
index d95bf904c3b3fb40438335198a2729e45a9897cb..fce9e5c0f6e0d94ff2e5fc27ade0c005e2e728e7 100644 (file)
@@ -168,7 +168,7 @@ static int add(int argc, const char **argv)
                OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
                { OPTION_CALLBACK, 0, "mirror", &mirror, N_("push|fetch"),
                        N_("set up remote as a mirror to push to or fetch from"),
-                       PARSE_OPT_OPTARG, parse_mirror_opt },
+                       PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt },
                OPT_END()
        };
 
index 29f4defdd6f2a85604d429d0278e0997378077b2..979577ba2c7a045ddd098f3bfb5cfb96706599d3 100644 (file)
@@ -459,6 +459,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
                default:
                        break;
                }
+               if (opts->flags & PARSE_OPT_COMP_ARG)
+                       suffix = "=";
                printf(" --%s%s", opts->long_name, suffix);
        }
        fputc('\n', stdout);
index 009cd863e5b0aa50af365dc027d89baf9c44e953..0ba08691e650db0f519e5a67b647b89ef089a74f 100644 (file)
@@ -39,7 +39,8 @@ enum parse_opt_option_flags {
        PARSE_OPT_NODASH = 32,
        PARSE_OPT_LITERAL_ARGHELP = 64,
        PARSE_OPT_SHELL_EVAL = 256,
-       PARSE_OPT_NOCOMPLETE = 512
+       PARSE_OPT_NOCOMPLETE = 512,
+       PARSE_OPT_COMP_ARG = 1024
 };
 
 struct option;
@@ -92,6 +93,9 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
  *                             Useful for options with multiple parameters.
  *   PARSE_OPT_NOCOMPLETE: by default all visible options are completable
  *                        by git-completion.bash. This option suppresses that.
+ *   PARSE_OPT_COMP_ARG: this option forces to git-completion.bash to
+ *                      complete an option as --name= not --name even if
+ *                      the option takes optional argument.
  *
  * `callback`::
  *   pointer to the callback to use for OPTION_CALLBACK or