Skip to content

Commit c852bd5

Browse files
peffgitster
authored andcommitted
add--interactive: fix missing file prompt for patch mode with "-i"
When invoked as "git add -i", each menu interactive menu option prompts the user to select a list of files. This includes the "patch" option, which gets the list before starting the hunk-selection loop. As "git add -p", it behaves differently, and jumps straight to the hunk selection loop. Since 0539d5e (i18n: add--interactive: mark patch prompt for translation, 2016-12-14), the "add -i" case mistakenly jumps to straight to the hunk-selection loop. Prior to that commit the distinction between the two cases was managed by the $patch_mode variable. That commit used $patch_mode for something else, and moved the old meaning to the "$cmd" variable. But it forgot to update the $patch_mode check inside patch_update_cmd() which controls the file-list behavior. The simplest fix would be to change that line to check $cmd. But while we're here, let's use a less obscure name for this flag: $patch_mode_only, a boolean which tells whether we are in full-interactive mode or only in patch-mode. Reported-by: Henrik Grubbström <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7e07d5 commit c852bd5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

git-add--interactive.perl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ sub colored {
9292
}
9393

9494
# command line options
95-
my $cmd;
95+
my $patch_mode_only;
9696
my $patch_mode;
9797
my $patch_mode_revision;
9898

@@ -1299,7 +1299,7 @@ sub patch_update_cmd {
12991299
}
13001300
return 0;
13011301
}
1302-
if ($patch_mode) {
1302+
if ($patch_mode_only) {
13031303
@them = @mods;
13041304
}
13051305
else {
@@ -1721,7 +1721,7 @@ sub process_args {
17211721
die sprintf(__("invalid argument %s, expecting --"),
17221722
$arg) unless $arg eq "--";
17231723
%patch_mode_flavour = %{$patch_modes{$patch_mode}};
1724-
$cmd = 1;
1724+
$patch_mode_only = 1;
17251725
}
17261726
elsif ($arg ne "--") {
17271727
die sprintf(__("invalid argument %s, expecting --"), $arg);
@@ -1758,7 +1758,7 @@ sub main_loop {
17581758

17591759
process_args();
17601760
refresh();
1761-
if ($cmd) {
1761+
if ($patch_mode_only) {
17621762
patch_update_cmd();
17631763
}
17641764
else {

t/t3701-add-interactive.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,22 @@ test_expect_success 'diffs can be colorized' '
394394
grep "$(printf "\\033")" output
395395
'
396396

397+
test_expect_success 'patch-mode via -i prompts for files' '
398+
git reset --hard &&
399+
400+
echo one >file &&
401+
echo two >test &&
402+
git add -i <<-\EOF &&
403+
patch
404+
test
405+
406+
y
407+
quit
408+
EOF
409+
410+
echo test >expect &&
411+
git diff --cached --name-only >actual &&
412+
test_cmp expect actual
413+
'
414+
397415
test_done

0 commit comments

Comments
 (0)