Skip to content

Commit 93de1b6

Browse files
avargitster
authored andcommitted
help: don't print "\n" before single-section output
Fix a formatting regression in 1b81d8c (help: use command-list.txt for the source of guides, 2018-05-20). Adjust the output of "git help --guides" and any other future single-section commands so that a newline isn't inserted before the only section being printed. This changes the output from: $ git help --guides The Git concept guides are: [...] To: $ git help --guides The Git concept guides are: [...] That we started printing an extra "\n" in 1b81d8c wasn't intended, but an emergent effect of moving all of the printing of "git help" output to code that was ready to handle printing N sections. With 1b81d8c we started using the "print_cmd_by_category()" function added earlier in the same series, or in cfb22a0 (help: use command-list.h for common command list, 2018-05-10). Fixing this formatting nit is easy enough. Let's have all of the output that would like to be "\n"-separated from other lines emit its own "\n". We then adjust "print_cmd_by_category()" to only print a "\n" to delimit the sections it's printing out. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ce5901 commit 93de1b6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

help.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ static void print_cmd_by_category(const struct category_description *catdesc,
124124
uint32_t mask = catdesc[i].category;
125125
const char *desc = catdesc[i].desc;
126126

127-
putchar('\n');
127+
if (i)
128+
putchar('\n');
128129
puts(_(desc));
129130
print_command_list(cmds, mask, longest);
130131
}
@@ -328,6 +329,7 @@ void list_commands(struct cmdnames *main_cmds, struct cmdnames *other_cmds)
328329
void list_common_cmds_help(void)
329330
{
330331
puts(_("These are common Git commands used in various situations:"));
332+
putchar('\n');
331333
print_cmd_by_category(common_categories, NULL);
332334
}
333335

@@ -481,6 +483,7 @@ void list_all_cmds_help(int show_external_commands, int show_aliases)
481483
int longest;
482484

483485
puts(_("See 'git help <command>' to read about a specific subcommand"));
486+
putchar('\n');
484487
print_cmd_by_category(main_categories, &longest);
485488

486489
if (show_external_commands)

t/t0012-help.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ test_expect_success "'git help -a' section spacing" '
226226

227227
test_expect_success "'git help -g' section spacing" '
228228
test_section_spacing_trailer git help -g <<-\EOF &&
229-
230229
The Git concept guides are:
231230
232231
EOF

0 commit comments

Comments
 (0)