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 0539d5e6d
(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 <grubba@grubba.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e7e07d5a4f
commit
c852bd54bd
@ -92,7 +92,7 @@ sub colored {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# command line options
|
# command line options
|
||||||
my $cmd;
|
my $patch_mode_only;
|
||||||
my $patch_mode;
|
my $patch_mode;
|
||||||
my $patch_mode_revision;
|
my $patch_mode_revision;
|
||||||
|
|
||||||
@ -1299,7 +1299,7 @@ sub patch_update_cmd {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ($patch_mode) {
|
if ($patch_mode_only) {
|
||||||
@them = @mods;
|
@them = @mods;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1721,7 +1721,7 @@ sub process_args {
|
|||||||
die sprintf(__("invalid argument %s, expecting --"),
|
die sprintf(__("invalid argument %s, expecting --"),
|
||||||
$arg) unless $arg eq "--";
|
$arg) unless $arg eq "--";
|
||||||
%patch_mode_flavour = %{$patch_modes{$patch_mode}};
|
%patch_mode_flavour = %{$patch_modes{$patch_mode}};
|
||||||
$cmd = 1;
|
$patch_mode_only = 1;
|
||||||
}
|
}
|
||||||
elsif ($arg ne "--") {
|
elsif ($arg ne "--") {
|
||||||
die sprintf(__("invalid argument %s, expecting --"), $arg);
|
die sprintf(__("invalid argument %s, expecting --"), $arg);
|
||||||
@ -1758,7 +1758,7 @@ sub main_loop {
|
|||||||
|
|
||||||
process_args();
|
process_args();
|
||||||
refresh();
|
refresh();
|
||||||
if ($cmd) {
|
if ($patch_mode_only) {
|
||||||
patch_update_cmd();
|
patch_update_cmd();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -394,4 +394,22 @@ test_expect_success 'diffs can be colorized' '
|
|||||||
grep "$(printf "\\033")" output
|
grep "$(printf "\\033")" output
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'patch-mode via -i prompts for files' '
|
||||||
|
git reset --hard &&
|
||||||
|
|
||||||
|
echo one >file &&
|
||||||
|
echo two >test &&
|
||||||
|
git add -i <<-\EOF &&
|
||||||
|
patch
|
||||||
|
test
|
||||||
|
|
||||||
|
y
|
||||||
|
quit
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo test >expect &&
|
||||||
|
git diff --cached --name-only >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user