Skip to content

Commit 7c28058

Browse files
committed
parse-options: teach "git cmd -h" to show alias as alias
There is a long-standing NEEDSWORK comment that complains about inconsistency between how an aliased option ("git clone --recurse" which is the only one that currently exists) gives a help text in a usage-error message vs "git cmd -h"). Get rid of it and then make sure we say an option is an alias for another, instead of repeating the same short help text for both, which leads to "they seem to do the same---is there any subtle difference?" puzzlement to end-users. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c85aac commit 7c28058

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

parse-options.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
648648
int short_name;
649649
const char *long_name;
650650
const char *source;
651+
struct strbuf help = STRBUF_INIT;
651652
int j;
652653

653654
if (newopt[i].type != OPTION_ALIAS)
@@ -659,6 +660,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
659660

660661
if (!long_name)
661662
BUG("An alias must have long option name");
663+
strbuf_addf(&help, _("alias of --%s"), source);
662664

663665
for (j = 0; j < nr; j++) {
664666
const char *name = options[j].long_name;
@@ -669,15 +671,10 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
669671
if (options[j].type == OPTION_ALIAS)
670672
BUG("No please. Nested aliases are not supported.");
671673

672-
/*
673-
* NEEDSWORK: this is a bit inconsistent because
674-
* usage_with_options() on the original options[] will print
675-
* help string as "alias of %s" but "git cmd -h" will
676-
* print the original help string.
677-
*/
678674
memcpy(newopt + i, options + j, sizeof(*newopt));
679675
newopt[i].short_name = short_name;
680676
newopt[i].long_name = long_name;
677+
newopt[i].help = strbuf_detach(&help, NULL);
681678
break;
682679
}
683680

t/t0040-parse-options.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Alias
5454
-A, --alias-source <string>
5555
get a string
5656
-Z, --alias-target <string>
57-
get a string
57+
alias of --alias-source
5858
5959
EOF
6060

0 commit comments

Comments
 (0)