Skip to content

Commit 2241477

Browse files
Sébastien Guimmaragitster
authored andcommitted
help: respect new common command grouping
'git help' shows common commands in alphabetical order: The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository [...] without any indication of how commands relate to high-level concepts or each other. Revise the output to explain their relationship with the typical Git workflow: These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize [...] work on the current change (see also: git help everyday) add Add file contents to the index reset Reset current HEAD to the specified state examine the history and state (see also: git help revisions) log Show commit logs status Show the working tree status [...] Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Sébastien Guimmara <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f5b495 commit 2241477

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

help.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,39 @@ void list_commands(unsigned int colopts,
218218
}
219219
}
220220

221+
static int cmd_group_cmp(const void *elem1, const void *elem2)
222+
{
223+
const struct cmdname_help *e1 = elem1;
224+
const struct cmdname_help *e2 = elem2;
225+
226+
if (e1->group < e2->group)
227+
return -1;
228+
if (e1->group > e2->group)
229+
return 1;
230+
return strcmp(e1->name, e2->name);
231+
}
232+
221233
void list_common_cmds_help(void)
222234
{
223235
int i, longest = 0;
236+
int current_grp = -1;
224237

225238
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
226239
if (longest < strlen(common_cmds[i].name))
227240
longest = strlen(common_cmds[i].name);
228241
}
229242

230-
puts(_("The most commonly used git commands are:"));
243+
qsort(common_cmds, ARRAY_SIZE(common_cmds),
244+
sizeof(common_cmds[0]), cmd_group_cmp);
245+
246+
puts(_("These are common Git commands used in various situations:"));
247+
231248
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
249+
if (common_cmds[i].group != current_grp) {
250+
printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group]));
251+
current_grp = common_cmds[i].group;
252+
}
253+
232254
printf(" %s ", common_cmds[i].name);
233255
mput_char(' ', longest - strlen(common_cmds[i].name));
234256
puts(_(common_cmds[i].help));

0 commit comments

Comments
 (0)