Skip to content

Commit 481e331

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 3e1a88d commit 481e331

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
@@ -439,6 +439,27 @@ static int run_status(struct repository *r, const struct pathspec *ps,
439439
return 0;
440440
}
441441

442+
static int run_help(struct repository *r, const struct pathspec *ps,
443+
struct file_list *files, struct list_options *opts)
444+
{
445+
const char *help_color = get_add_i_color(COLOR_HELP);
446+
447+
color_fprintf_ln(stdout, help_color, "status - %s",
448+
_("show paths with changes"));
449+
color_fprintf_ln(stdout, help_color, "update - %s",
450+
_("add working tree state to the staged set of changes"));
451+
color_fprintf_ln(stdout, help_color, "revert - %s",
452+
_("revert staged set of changes back to the HEAD version"));
453+
color_fprintf_ln(stdout, help_color, "patch - %s",
454+
_("pick hunks and update selectively"));
455+
color_fprintf_ln(stdout, help_color, "diff - %s",
456+
_("view diff between HEAD and index"));
457+
color_fprintf_ln(stdout, help_color, "add untracked - %s",
458+
_("add contents of untracked files to the staged set of changes"));
459+
460+
return 0;
461+
}
462+
442463
struct print_command_item_data {
443464
const char *color, *reset;
444465
};
@@ -490,9 +511,11 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
490511
N_("What now"), command_prompt_help
491512
};
492513
struct command_item
493-
status = { { "status" }, run_status };
514+
status = { { "status" }, run_status },
515+
help = { { "help" }, run_help };
494516
struct command_item *commands[] = {
495-
&status
517+
&status,
518+
&help
496519
};
497520

498521
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)