Skip to content

Commit ebc4a04

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab6a11c commit ebc4a04

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int add(int argc, const char **argv)
168168
OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
169169
{ OPTION_CALLBACK, 0, "mirror", &mirror, N_("push|fetch"),
170170
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 },
172172
OPT_END()
173173
};
174174

parse-options.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
459459
default:
460460
break;
461461
}
462+
if (opts->flags & PARSE_OPT_COMP_ARG)
463+
suffix = "=";
462464
printf(" --%s%s", opts->long_name, suffix);
463465
}
464466
fputc('\n', stdout);

parse-options.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ enum parse_opt_option_flags {
3939
PARSE_OPT_NODASH = 32,
4040
PARSE_OPT_LITERAL_ARGHELP = 64,
4141
PARSE_OPT_SHELL_EVAL = 256,
42-
PARSE_OPT_NOCOMPLETE = 512
42+
PARSE_OPT_NOCOMPLETE = 512,
43+
PARSE_OPT_COMP_ARG = 1024
4344
};
4445

4546
struct option;
@@ -92,6 +93,9 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
9293
* Useful for options with multiple parameters.
9394
* PARSE_OPT_NOCOMPLETE: by default all visible options are completable
9495
* 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.
9599
*
96100
* `callback`::
97101
* pointer to the callback to use for OPTION_CALLBACK or

0 commit comments

Comments
 (0)