@@ -100,8 +100,8 @@ static struct option builtin_clone_options[] = {
N_("setup as shared repository")),
{ OPTION_CALLBACK, 0, "recursive", &option_recurse_submodules,
N_("pathspec"), N_("initialize submodules in the clone"),
- PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, recurse_submodules_cb,
- (intptr_t)"." },
+ PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN | PARSE_OPT_NOCOMPLETE,
+ recurse_submodules_cb, (intptr_t)"." },
{ OPTION_CALLBACK, 0, "recurse-submodules", &option_recurse_submodules,
N_("pathspec"), N_("initialize submodules in the clone"),
PARSE_OPT_OPTARG, recurse_submodules_cb, (intptr_t)"." },
@@ -294,7 +294,8 @@ static enum parse_opt_result parse_long_opt(
if (!rest) {
/* abbreviated? */
if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
- !strncmp(long_name, arg, arg_end - arg)) {
+ !strncmp(long_name, arg, arg_end - arg) &&
+ !(options->flags & PARSE_OPT_NOCOMPLETE)) {
is_abbreviated:
if (abbrev_option) {
/*
@@ -96,6 +96,8 @@ typedef enum parse_opt_result 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.
+ * Will also skip this option when abbreviation is
+ * considered. See core.abbreviatedOptions.
* 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.
@@ -236,6 +236,11 @@ test_expect_success 'abbreviated options configured with core.abbreviatedOptions
git -c core.abbreviatedOptions=true init --ba C
'
+test_expect_success 'NOCOMPLETE options do not contribute to abbreviation' '
+ test_when_finished "rm -rf A" &&
+ GIT_TEST_ABBREVIATED_OPTIONS=true git clone --recurs . A
+'
+
cat >typo.err <<\EOF
error: did you mean `--boolean` (with two dashes ?)
EOF
Change the option parsing machinery so that e.g. "clone --recurs ..." doesn't error out because "clone" understands both "--recursive" and "--recurse-submodules" to mean the same thing. Initially "clone" just understood --recursive until the --recurses-submodules alias was added in ccdd3da652 ("clone: Add the --recurse-submodules option as alias for --recursive", 2010-11-04). Since bb62e0a99f ("clone: teach --recurse-submodules to optionally take a pathspec", 2017-03-17) the longer form has been promoted to the default. But due to the way the options parsing machinery works this resulted in the rather absurd situation of: $ git clone --recurs [...] error: ambiguous option: recurs (could be --recursive or --recurse-submodules) Let's re-use the PARSE_OPT_NOCOMPLETE flag to mean "this option doesn't contribute to abbreviation ambiguity". I was going to add a new PARSE_OPT_NOABBREV flag, but it makes sense just to re-use PARSE_OPT_NOCOMPLETE. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/clone.c | 4 ++-- parse-options.c | 3 ++- parse-options.h | 2 ++ t/t0040-parse-options.sh | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-)