Skip to content

Commit ddb913e

Browse files
committed
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]>
1 parent 9cf3260 commit ddb913e

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

add-interactive.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,27 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
422422
return 0;
423423
}
424424

425+
static int run_help(struct add_i_state *s, const struct pathspec *ps,
426+
struct file_list *files, struct list_options *opts)
427+
{
428+
const char *help_color = s->help_color;
429+
430+
color_fprintf_ln(stdout, help_color, "status - %s",
431+
_("show paths with changes"));
432+
color_fprintf_ln(stdout, help_color, "update - %s",
433+
_("add working tree state to the staged set of changes"));
434+
color_fprintf_ln(stdout, help_color, "revert - %s",
435+
_("revert staged set of changes back to the HEAD version"));
436+
color_fprintf_ln(stdout, help_color, "patch - %s",
437+
_("pick hunks and update selectively"));
438+
color_fprintf_ln(stdout, help_color, "diff - %s",
439+
_("view diff between HEAD and index"));
440+
color_fprintf_ln(stdout, help_color, "add untracked - %s",
441+
_("add contents of untracked files to the staged set of changes"));
442+
443+
return 0;
444+
}
445+
425446
struct print_command_item_data {
426447
const char *color, *reset;
427448
};
@@ -467,9 +488,11 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
467488
N_("What now"), command_prompt_help
468489
};
469490
struct command_item
470-
status = { { "status" }, run_status };
491+
status = { { "status" }, run_status },
492+
help = { { "help" }, run_help };
471493
struct command_item *commands[] = {
472-
&status
494+
&status,
495+
&help
473496
};
474497

475498
struct print_file_item_data print_file_item_data = {

t/t3701-add-interactive.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,28 @@ test_expect_success 'add -p patch editing works with pathological context lines'
639639
test_cmp expected-2 actual
640640
'
641641

642+
test_expect_success 'show help from add--helper' '
643+
git reset --hard &&
644+
cat >expect <<-EOF &&
645+
646+
<BOLD>*** Commands ***<RESET>
647+
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
648+
5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
649+
<BOLD;BLUE>What now<RESET>> <BOLD;RED>status - show paths with changes<RESET>
650+
<BOLD;RED>update - add working tree state to the staged set of changes<RESET>
651+
<BOLD;RED>revert - revert staged set of changes back to the HEAD version<RESET>
652+
<BOLD;RED>patch - pick hunks and update selectively<RESET>
653+
<BOLD;RED>diff - view diff between HEAD and index<RESET>
654+
<BOLD;RED>add untracked - add contents of untracked files to the staged set of changes<RESET>
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>>$SP
659+
Bye.
660+
EOF
661+
test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored &&
662+
test_decode_color <actual.colored >actual &&
663+
test_i18ncmp expect actual
664+
'
665+
642666
test_done

0 commit comments

Comments
 (0)