Skip to content

Commit 4504107

Browse files
thenigangitster
authored andcommitted
git remote: Separate usage strings for subcommands
When the usage string for a subcommand must be printed, only print the information relevant to that command. This commit also removes the complete options list from the first line of the subcommand usage string. Instead, individual options are documented in the detailed description following the general usage line. Signed-off-by: Tim Henigan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78d553b commit 4504107

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

Documentation/git-remote.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ SYNOPSIS
1313
'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
1414
'git remote rename' <old> <new>
1515
'git remote rm' <name>
16-
'git remote set-head' <name> [-a | -d | <branch>]
17-
'git remote show' [-n] <name>
16+
'git remote set-head' <name> (-a | -d | <branch>)
17+
'git remote' [-v | --verbose] 'show' [-n] <name>
1818
'git remote prune' [-n | --dry-run] <name>
19-
'git remote update' [-p | --prune] [group | remote]...
19+
'git remote' [-v | --verbose] 'update' [-p | --prune] [group | remote]...
2020

2121
DESCRIPTION
2222
-----------
@@ -30,6 +30,7 @@ OPTIONS
3030
-v::
3131
--verbose::
3232
Be a little more verbose and show remote url after name.
33+
NOTE: This must be placed between `remote` and `subcommand`.
3334

3435

3536
COMMANDS

builtin-remote.c

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,48 @@ static const char * const builtin_remote_usage[] = {
1212
"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>",
1313
"git remote rename <old> <new>",
1414
"git remote rm <name>",
15-
"git remote set-head <name> [-a | -d | <branch>]",
16-
"git remote show [-n] <name>",
15+
"git remote set-head <name> (-a | -d | <branch>)",
16+
"git remote [-v | --verbose] show [-n] <name>",
1717
"git remote prune [-n | --dry-run] <name>",
1818
"git remote [-v | --verbose] update [-p | --prune] [group]",
1919
NULL
2020
};
2121

22+
static const char * const builtin_remote_add_usage[] = {
23+
"git remote add [<options>] <name> <url>",
24+
NULL
25+
};
26+
27+
static const char * const builtin_remote_rename_usage[] = {
28+
"git remote rename <old> <new>",
29+
NULL
30+
};
31+
32+
static const char * const builtin_remote_rm_usage[] = {
33+
"git remote rm <name>",
34+
NULL
35+
};
36+
37+
static const char * const builtin_remote_sethead_usage[] = {
38+
"git remote set-head <name> (-a | -d | <branch>])",
39+
NULL
40+
};
41+
42+
static const char * const builtin_remote_show_usage[] = {
43+
"git remote show [<options>] <name>",
44+
NULL
45+
};
46+
47+
static const char * const builtin_remote_prune_usage[] = {
48+
"git remote prune [<options>] <name>",
49+
NULL
50+
};
51+
52+
static const char * const builtin_remote_update_usage[] = {
53+
"git remote update [<options>] [<group> | <remote>]...",
54+
NULL
55+
};
56+
2257
#define GET_REF_STATES (1<<0)
2358
#define GET_HEAD_NAMES (1<<1)
2459
#define GET_PUSH_REF_STATES (1<<2)
@@ -70,7 +105,6 @@ static int add(int argc, const char **argv)
70105
int i;
71106

72107
struct option options[] = {
73-
OPT_GROUP("add specific options"),
74108
OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
75109
OPT_CALLBACK('t', "track", &track, "branch",
76110
"branch(es) to track", opt_parse_track),
@@ -79,11 +113,11 @@ static int add(int argc, const char **argv)
79113
OPT_END()
80114
};
81115

82-
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
116+
argc = parse_options(argc, argv, NULL, options, builtin_remote_add_usage,
83117
0);
84118

85119
if (argc < 2)
86-
usage_with_options(builtin_remote_usage, options);
120+
usage_with_options(builtin_remote_add_usage, options);
87121

88122
name = argv[0];
89123
url = argv[1];
@@ -540,7 +574,7 @@ static int mv(int argc, const char **argv)
540574
int i;
541575

542576
if (argc != 3)
543-
usage_with_options(builtin_remote_usage, options);
577+
usage_with_options(builtin_remote_rename_usage, options);
544578

545579
rename.old = argv[1];
546580
rename.new = argv[2];
@@ -681,7 +715,7 @@ static int rm(int argc, const char **argv)
681715
int i, result;
682716

683717
if (argc != 2)
684-
usage_with_options(builtin_remote_usage, options);
718+
usage_with_options(builtin_remote_rm_usage, options);
685719

686720
remote = remote_get(argv[1]);
687721
if (!remote)
@@ -976,15 +1010,14 @@ static int show(int argc, const char **argv)
9761010
{
9771011
int no_query = 0, result = 0, query_flag = 0;
9781012
struct option options[] = {
979-
OPT_GROUP("show specific options"),
9801013
OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
9811014
OPT_END()
9821015
};
9831016
struct ref_states states;
9841017
struct string_list info_list = { NULL, 0, 0, 0 };
9851018
struct show_info info;
9861019

987-
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1020+
argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
9881021
0);
9891022

9901023
if (argc < 1)
@@ -1081,14 +1114,13 @@ static int set_head(int argc, const char **argv)
10811114
char *head_name = NULL;
10821115

10831116
struct option options[] = {
1084-
OPT_GROUP("set-head specific options"),
10851117
OPT_BOOLEAN('a', "auto", &opt_a,
10861118
"set refs/remotes/<name>/HEAD according to remote"),
10871119
OPT_BOOLEAN('d', "delete", &opt_d,
10881120
"delete refs/remotes/<name>/HEAD"),
10891121
OPT_END()
10901122
};
1091-
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1123+
argc = parse_options(argc, argv, NULL, options, builtin_remote_sethead_usage,
10921124
0);
10931125
if (argc)
10941126
strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
@@ -1114,7 +1146,7 @@ static int set_head(int argc, const char **argv)
11141146
if (delete_ref(buf.buf, NULL, REF_NODEREF))
11151147
result |= error("Could not delete %s", buf.buf);
11161148
} else
1117-
usage_with_options(builtin_remote_usage, options);
1149+
usage_with_options(builtin_remote_sethead_usage, options);
11181150

11191151
if (head_name) {
11201152
unsigned char sha1[20];
@@ -1138,16 +1170,15 @@ static int prune(int argc, const char **argv)
11381170
{
11391171
int dry_run = 0, result = 0;
11401172
struct option options[] = {
1141-
OPT_GROUP("prune specific options"),
11421173
OPT__DRY_RUN(&dry_run),
11431174
OPT_END()
11441175
};
11451176

1146-
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1177+
argc = parse_options(argc, argv, NULL, options, builtin_remote_prune_usage,
11471178
0);
11481179

11491180
if (argc < 1)
1150-
usage_with_options(builtin_remote_usage, options);
1181+
usage_with_options(builtin_remote_prune_usage, options);
11511182

11521183
for (; argc; argc--, argv++)
11531184
result |= prune_remote(*argv, dry_run);
@@ -1228,13 +1259,12 @@ static int update(int argc, const char **argv)
12281259
struct string_list list = { NULL, 0, 0, 0 };
12291260
static const char *default_argv[] = { NULL, "default", NULL };
12301261
struct option options[] = {
1231-
OPT_GROUP("update specific options"),
12321262
OPT_BOOLEAN('p', "prune", &prune,
12331263
"prune remotes after fetching"),
12341264
OPT_END()
12351265
};
12361266

1237-
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
1267+
argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage,
12381268
PARSE_OPT_KEEP_ARGV0);
12391269
if (argc < 2) {
12401270
argc = 2;
@@ -1334,7 +1364,7 @@ static int show_all(void)
13341364
int cmd_remote(int argc, const char **argv, const char *prefix)
13351365
{
13361366
struct option options[] = {
1337-
OPT__VERBOSE(&verbose),
1367+
OPT_BOOLEAN('v', "verbose", &verbose, "be verbose; must be placed before a subcommand"),
13381368
OPT_END()
13391369
};
13401370
int result;

0 commit comments

Comments
 (0)