Skip to content

Commit 92330dd

Browse files
slavicaDjdscho
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]>
1 parent 293d958 commit 92330dd

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
@@ -508,6 +508,26 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
508508
return 0;
509509
}
510510

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+
511531
typedef int (*command_t)(struct add_i_state *s, const struct pathspec *ps,
512532
struct string_list *files,
513533
struct list_options *opts);
@@ -561,6 +581,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
561581
command_t command;
562582
} command_list[] = {
563583
{ "status", run_status },
584+
{ "help", run_help },
564585
};
565586
struct prefix_item_list commands = PREFIX_ITEM_LIST_INIT;
566587

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)