Skip to content

Commit 4bdd6e7

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88f6ffc commit 4bdd6e7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

git-add--interactive.perl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,12 @@ sub patch_update_file {
14371437
}
14381438
next;
14391439
}
1440-
elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
1440+
elsif ($line =~ /^g(.*)/) {
14411441
my $response = $1;
1442+
unless ($other =~ /g/) {
1443+
error_msg __("No other hunks to goto\n");
1444+
next;
1445+
}
14421446
my $no = $ix > 10 ? $ix - 10 : 0;
14431447
while ($response eq '') {
14441448
$no = display_hunks(\@hunk, $no);
@@ -1556,7 +1560,11 @@ sub patch_update_file {
15561560
next;
15571561
}
15581562
}
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+
}
15601568
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
15611569
if (1 < @split) {
15621570
print colored $header_color, sprintf(
@@ -1568,7 +1576,11 @@ sub patch_update_file {
15681576
$num = scalar @hunk;
15691577
next;
15701578
}
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+
}
15721584
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
15731585
if (defined $newhunk) {
15741586
splice @hunk, $ix, 1, $newhunk;

0 commit comments

Comments
 (0)