Skip to content

Commit 2b5d5c1

Browse files
slavicaDjgitster
authored andcommitted
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ć <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 91c54d9 commit 2b5d5c1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

add-interactive.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,26 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
507507
return 0;
508508
}
509509

510+
static int run_help(struct add_i_state *s, const struct pathspec *unused_ps,
511+
struct string_list *unused_files,
512+
struct list_options *unused_opts)
513+
{
514+
color_fprintf_ln(stdout, s->help_color, "status - %s",
515+
_("show paths with changes"));
516+
color_fprintf_ln(stdout, s->help_color, "update - %s",
517+
_("add working tree state to the staged set of changes"));
518+
color_fprintf_ln(stdout, s->help_color, "revert - %s",
519+
_("revert staged set of changes back to the HEAD version"));
520+
color_fprintf_ln(stdout, s->help_color, "patch - %s",
521+
_("pick hunks and update selectively"));
522+
color_fprintf_ln(stdout, s->help_color, "diff - %s",
523+
_("view diff between HEAD and index"));
524+
color_fprintf_ln(stdout, s->help_color, "add untracked - %s",
525+
_("add contents of untracked files to the staged set of changes"));
526+
527+
return 0;
528+
}
529+
510530
typedef int (*command_t)(struct add_i_state *s, const struct pathspec *ps,
511531
struct string_list *files,
512532
struct list_options *opts);
@@ -560,6 +580,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
560580
command_t command;
561581
} command_list[] = {
562582
{ "status", run_status },
583+
{ "help", run_help },
563584
};
564585
struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
565586

t/t3701-add-interactive.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,29 @@ test_expect_success 'checkout -p works with pathological context lines' '
647647
test_write_lines a b a b a a b a b a >expect &&
648648
test_cmp expect a
649649
'
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+
650675
test_done

0 commit comments

Comments
 (0)