Skip to content

Commit b8f458c

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 03ef60b commit b8f458c

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

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

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)