add -p: improve error messages
If the user presses a key that isn't currently active then explain why it isn't active rather than just listing all the keys. It already did this for some keys, this patch does the same for the those that weren't already handled. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Feb 13, 2018 at 10:32 UTC
4bdd6e7ce33c72dfaa79c4139d30bd809ec8eda7
1 file changed
+15
-3
git-add--interactive.perl
+15
-3
@@ -1437,8 +1437,12 @@ sub patch_update_file {
1437
}
1438
next;
1439
}
1440
- elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1440
+ elsif ($line =~ /^g(.*)/) {
1441
my $response = $1;
1442
+ unless ($other =~ /g/) {
1443
+ error_msg __("No other hunks to goto\n");
1444
+ next;
1445
+ }
1446
my $no = $ix > 10 ? $ix - 10 : 0;
1447
while ($response eq '') {
1448
$no = display_hunks(\@hunk, $no);
@@ -1556,7 +1560,11 @@ sub patch_update_file {
1560
next;
1561
}
1562
}
1559
- elsif ($other =~ /s/ && $line =~ /^s/) {
1563
+ elsif ($line =~ /^s/) {
1564
+ unless ($other =~ /s/) {
1565
+ error_msg __("Sorry, cannot split this hunk\n");
1566
+ next;
1567
+ }
1568
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
1569
if (1 < @split) {
1570
print colored $header_color, sprintf(
@@ -1568,7 +1576,11 @@ sub patch_update_file {
1576
$num = scalar @hunk;
1577
next;
1578
}
1571
- elsif ($other =~ /e/ && $line =~ /^e/) {
1579
+ elsif ($line =~ /^e/) {
1580
+ unless ($other =~ /e/) {
1581
+ error_msg __("Sorry, cannot edit this hunk\n");
1582
+ next;
1583
+ }
1584
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
1585
if (defined $newhunk) {
1586
splice @hunk, $ix, 1, $newhunk;