@matheusbsbs / matheus-bagliano / commits / 8c15904462
Fork 0

built-in add -i: implement the `help` command

This imitates the code to show the help text from the Perl script `git-add--interactive.perl` in the built-in version. To make sure that it renders exactly like the Perl version of `git add -i`, we also add a test case for that to `t3701-add-interactive.sh`. Signed-off-by: Slavica Đukić <slawica92@hotmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Slavica Đukić committed Nov 15, 2019 at 11:11 UTC 8c159044625e46de67cd8467f07424f38eb8301e
2 files changed +46
add-interactive.c
+21
@@ -508,6 +508,26 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
508 return 0;
509 }
510
511 +static int run_help(struct add_i_state *s, const struct pathspec *unused_ps,
512 + struct string_list *unused_files,
513 + struct list_options *unused_opts)
514 +{
515 + color_fprintf_ln(stdout, s->help_color, "status - %s",
516 + _("show paths with changes"));
517 + color_fprintf_ln(stdout, s->help_color, "update - %s",
518 + _("add working tree state to the staged set of changes"));
519 + color_fprintf_ln(stdout, s->help_color, "revert - %s",
520 + _("revert staged set of changes back to the HEAD version"));
521 + color_fprintf_ln(stdout, s->help_color, "patch - %s",
522 + _("pick hunks and update selectively"));
523 + color_fprintf_ln(stdout, s->help_color, "diff - %s",
524 + _("view diff between HEAD and index"));
525 + color_fprintf_ln(stdout, s->help_color, "add untracked - %s",
526 + _("add contents of untracked files to the staged set of changes"));
527 +
528 + return 0;
529 +}
530 +
531 typedef int (*command_t)(struct add_i_state *s, const struct pathspec *ps,
532 struct string_list *files,
533 struct list_options *opts);
@@ -561,6 +581,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
581 command_t command;
582 } command_list[] = {
583 { "status", run_status },
584 + { "help", run_help },
585 };
586 struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
587
t/t3701-add-interactive.sh
+25
@@ -647,4 +647,29 @@ test_expect_success 'checkout -p works with pathological context lines' '
647 test_write_lines a b a b a a b a b a >expect &&
648 test_cmp expect a
649 '
650 +
651 +test_expect_success 'show help from add--helper' '
652 + git reset --hard &&
653 + cat >expect <<-EOF &&
654 +
655 + <BOLD>*** Commands ***<RESET>
656 + 1: <BOLD;BLUE>s<RESET>tatus 2: <BOLD;BLUE>u<RESET>pdate 3: <BOLD;BLUE>r<RESET>evert 4: <BOLD;BLUE>a<RESET>dd untracked
657 + 5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
658 + <BOLD;BLUE>What now<RESET>> <BOLD;RED>status - show paths with changes<RESET>
659 + <BOLD;RED>update - add working tree state to the staged set of changes<RESET>
660 + <BOLD;RED>revert - revert staged set of changes back to the HEAD version<RESET>
661 + <BOLD;RED>patch - pick hunks and update selectively<RESET>
662 + <BOLD;RED>diff - view diff between HEAD and index<RESET>
663 + <BOLD;RED>add untracked - add contents of untracked files to the staged set of changes<RESET>
664 + <BOLD>*** Commands ***<RESET>
665 + 1: <BOLD;BLUE>s<RESET>tatus 2: <BOLD;BLUE>u<RESET>pdate 3: <BOLD;BLUE>r<RESET>evert 4: <BOLD;BLUE>a<RESET>dd untracked
666 + 5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
667 + <BOLD;BLUE>What now<RESET>>$SP
668 + Bye.
669 + EOF
670 + test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored &&
671 + test_decode_color <actual.colored >actual &&
672 + test_i18ncmp expect actual
673 +'
674 +
675 test_done