Skip to content

Commit

Permalink
parse-options: drop leading space from '--git-completion-helper' output
Browse files Browse the repository at this point in the history
The output of 'git <cmd> --git-completion-helper' always starts with a
space, e.g.:

  $ git config --git-completion-helper
   --global --system --local [...]

This doesn't matter for the completion script, because field splitting
discards that space anyway.

However, later patches in this series will teach parse-options to
handle subcommands, and subcommands will be included in the completion
helper output as well.  This will make the loop printing options (and
subcommands) a tad more complex, so I wanted to test the result.  The
test would have to account for the presence of that leading space,
which bugged my OCD, so let's get rid of it.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
szeder authored and gitster committed Aug 19, 2022
1 parent a9126b9 commit dc9f988
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ static int show_gitcomp(const struct option *opts, int show_all)
suffix = "=";
if (starts_with(opts->long_name, "no-"))
nr_noopts++;
printf(" --%s%s", opts->long_name, suffix);
printf("%s--%s%s", opts == original_opts ? "" : " ",
opts->long_name, suffix);
}
show_negated_gitcomp(original_opts, show_all, -1);
show_negated_gitcomp(original_opts, show_all, nr_noopts);
Expand Down

0 comments on commit dc9f988

Please sign in to comment.