Skip to content

Commit 371c45b

Browse files
committed
Merge branch 'dk/help-all' into seen
"git cmd --help-all" outside repository. Comments? * dk/help-all: builtin: also setup gently for --help-all parse-options: refactor flags for usage_with_options_internal t1517: fixup for ua/t1517-short-help-tests
2 parents 5a45004 + 4c8db1e commit 371c45b

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

builtin/merge-recursive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ int cmd_merge_recursive(int argc,
3838
if (argv[0] && ends_with(argv[0], "-subtree"))
3939
o.subtree_shift = "";
4040

41-
if (argc == 2 && !strcmp(argv[1], "-h")) {
41+
if (argc == 2 && (!strcmp(argv[1], "-h") ||
42+
!strcmp(argv[1], "--help-all"))) {
4243
struct strbuf msg = STRBUF_INIT;
4344
strbuf_addf(&msg, builtin_merge_recursive_usage, argv[0]);
4445
show_usage_if_asked(argc, argv, msg.buf);

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
445445
const char *prefix;
446446
int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY));
447447

448-
help = argc == 2 && !strcmp(argv[1], "-h");
448+
help = argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help-all"));
449449
if (help && (run_setup & RUN_SETUP))
450450
/* demote to GENTLY to allow 'git cmd -h' outside repo */
451451
run_setup = RUN_SETUP_GENTLY;

parse-options.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,16 @@ static void free_preprocessed_options(struct option *options)
953953
free(options);
954954
}
955955

956+
#define USAGE_NORMAL 0
957+
#define USAGE_FULL 1
958+
#define USAGE_TO_STDOUT 0
959+
#define USAGE_TO_STDERR 1
960+
956961
static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
957962
const char * const *,
958963
const struct option *,
959-
int, int);
964+
int full_usage,
965+
int usage_to_stderr);
960966

961967
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
962968
const struct option *options,
@@ -1088,7 +1094,8 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
10881094
}
10891095

10901096
if (internal_help && !strcmp(arg + 2, "help-all"))
1091-
return usage_with_options_internal(ctx, usagestr, options, 1, 0);
1097+
return usage_with_options_internal(ctx, usagestr, options,
1098+
USAGE_FULL, USAGE_TO_STDOUT);
10921099
if (internal_help && !strcmp(arg + 2, "help"))
10931100
goto show_usage;
10941101
switch (parse_long_opt(ctx, arg + 2, options)) {
@@ -1129,7 +1136,8 @@ enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
11291136
return PARSE_OPT_DONE;
11301137

11311138
show_usage:
1132-
return usage_with_options_internal(ctx, usagestr, options, 0, 0);
1139+
return usage_with_options_internal(ctx, usagestr, options,
1140+
USAGE_NORMAL, USAGE_TO_STDOUT);
11331141
}
11341142

11351143
int parse_options_end(struct parse_opt_ctx_t *ctx)
@@ -1444,17 +1452,25 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
14441452
void NORETURN usage_with_options(const char * const *usagestr,
14451453
const struct option *opts)
14461454
{
1447-
usage_with_options_internal(NULL, usagestr, opts, 0, 1);
1455+
usage_with_options_internal(NULL, usagestr, opts,
1456+
USAGE_NORMAL, USAGE_TO_STDERR);
14481457
exit(129);
14491458
}
14501459

14511460
void show_usage_with_options_if_asked(int ac, const char **av,
14521461
const char * const *usagestr,
14531462
const struct option *opts)
14541463
{
1455-
if (ac == 2 && !strcmp(av[1], "-h")) {
1456-
usage_with_options_internal(NULL, usagestr, opts, 0, 0);
1457-
exit(129);
1464+
if (ac == 2) {
1465+
if (!strcmp(av[1], "-h")) {
1466+
usage_with_options_internal(NULL, usagestr, opts,
1467+
USAGE_NORMAL, USAGE_TO_STDOUT);
1468+
exit(129);
1469+
} else if (!strcmp(av[1], "--help-all")) {
1470+
usage_with_options_internal(NULL, usagestr, opts,
1471+
USAGE_FULL, USAGE_TO_STDOUT);
1472+
exit(129);
1473+
}
14581474
}
14591475
}
14601476

t/t1517-outside-repo.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ do
123123
*)
124124
expect_outcome=expect_success ;;
125125
esac
126-
test_$expect_outcome "'git $cmd -h' outside a repository" '
126+
case "$cmd" in
127+
instaweb)
128+
prereq=PERL ;;
129+
*)
130+
prereq= ;;
131+
esac
132+
test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
127133
test_expect_code 129 nongit git $cmd -h >usage &&
128134
test_grep "[Uu]sage: git $cmd " usage
129135
'
136+
test_$expect_outcome $prereq "'git $cmd --help-all' outside a repository" '
137+
test_expect_code 129 nongit git $cmd --help-all >usage &&
138+
test_grep "[Uu]sage: git $cmd " usage
139+
'
130140
done
131141

132142
test_done

usage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ static void show_usage_if_asked_helper(const char *err, ...)
192192

193193
void show_usage_if_asked(int ac, const char **av, const char *err)
194194
{
195-
if (ac == 2 && !strcmp(av[1], "-h"))
195+
if (ac == 2 && (!strcmp(av[1], "-h") ||
196+
!strcmp(av[1], "--help-all")))
196197
show_usage_if_asked_helper(err);
197198
}
198199

0 commit comments

Comments
 (0)