Skip to content

Commit f3665cf

Browse files
dschogitster
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 Djukic <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 253cdc2 commit f3665cf

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

add-interactive.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,27 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
428428
return 0;
429429
}
430430

431+
static int run_help(struct add_i_state *s, const struct pathspec *ps,
432+
struct file_list *files, struct list_options *opts)
433+
{
434+
const char *help_color = s->help_color;
435+
436+
color_fprintf_ln(stdout, help_color, "status - %s",
437+
_("show paths with changes"));
438+
color_fprintf_ln(stdout, help_color, "update - %s",
439+
_("add working tree state to the staged set of changes"));
440+
color_fprintf_ln(stdout, help_color, "revert - %s",
441+
_("revert staged set of changes back to the HEAD version"));
442+
color_fprintf_ln(stdout, help_color, "patch - %s",
443+
_("pick hunks and update selectively"));
444+
color_fprintf_ln(stdout, help_color, "diff - %s",
445+
_("view diff between HEAD and index"));
446+
color_fprintf_ln(stdout, help_color, "add untracked - %s",
447+
_("add contents of untracked files to the staged set of changes"));
448+
449+
return 0;
450+
}
451+
431452
struct print_command_item_data {
432453
const char *color, *reset;
433454
};
@@ -473,9 +494,11 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
473494
N_("What now"), command_prompt_help
474495
};
475496
struct command_item
476-
status = { { "status" }, run_status };
497+
status = { { "status" }, run_status },
498+
help = { { "help" }, run_help };
477499
struct command_item *commands[] = {
478-
&status
500+
&status,
501+
&help
479502
};
480503

481504
struct print_file_item_data print_file_item_data = {

t/t3701-add-interactive.sh

+25
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)