git-add--interactive: Improve behavior on bogus input
1) Previously, any menu would cause a perl error when entered '0', which is never a valid option. 2) Entering a bogus choice (like 998 or 4-2) surprisingly caused the same behavior as if the user had just hit 'enter', which means to carry out the selected action on the selected items. Entering such bogus input is now a no-op and the sub-menu doesn't exit. Signed-off-by: Jean-Luc Herren <jlh@gmx.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jean-Luc Herren committed
Sep 26, 2007 at 16:05 UTC
6a6eb3d09fcbfae41978fb5223ae03e2d103968b
1 file changed
+3
-4
git-add--interactive.perl
+3
-4
@@ -219,7 +219,7 @@ sub list_and_choose {
219
last;
220
}
221
chomp $line;
222
- my $donesomething = 0;
222
+ last if $line eq '';
223
for my $choice (split(/[\s,]+/, $line)) {
224
my $choose = 1;
225
my ($bottom, $top);
@@ -251,12 +251,11 @@ sub list_and_choose {
251
next TOPLOOP;
252
}
253
for ($i = $bottom-1; $i <= $top-1; $i++) {
254
- next if (@stuff <= $i);
254
+ next if (@stuff <= $i || $i < 0);
255
$chosen[$i] = $choose;
256
- $donesomething++;
256
}
257
}
259
- last if (!$donesomething || $opts->{IMMEDIATE});
258
+ last if ($opts->{IMMEDIATE});
259
}
260
for ($i = 0; $i < @stuff; $i++) {
261
if ($chosen[$i]) {