Skip to content

Commit ace30ba

Browse files
wrpgitster
authored andcommitted
In add --patch, Handle K,k,J,j slightly more gracefully.
Instead of printing the help menu, this will print "No next hunk" and then process the given hunk again. Signed-off-by: William Pursell <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd971cc commit ace30ba

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

git-add--interactive.perl

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,29 +1039,42 @@ sub patch_update_file {
10391039
$ix = $iy;
10401040
next;
10411041
}
1042-
elsif ($other =~ /K/ && $line =~ /^K/) {
1043-
$ix--;
1042+
elsif ($line =~ /^K/) {
1043+
if ($other =~ /K/) {
1044+
$ix--;
1045+
}
1046+
else {
1047+
print STDERR "No previous hunk\n";
1048+
}
10441049
next;
10451050
}
1046-
elsif ($other =~ /J/ && $line =~ /^J/) {
1047-
$ix++;
1051+
elsif ($line =~ /^J/) {
1052+
if ($other =~ /J/) {
1053+
$ix++;
1054+
}
1055+
else {
1056+
print STDERR "No next hunk\n";
1057+
}
10481058
next;
10491059
}
1050-
elsif ($other =~ /k/ && $line =~ /^k/) {
1051-
while (1) {
1052-
$ix--;
1053-
last if (!$ix ||
1054-
!defined $hunk[$ix]{USE});
1060+
elsif ($line =~ /^k/) {
1061+
if ($other =~ /k/) {
1062+
while (1) {
1063+
$ix--;
1064+
last if (!$ix ||
1065+
!defined $hunk[$ix]{USE});
1066+
}
1067+
}
1068+
else {
1069+
print STDERR "No previous hunk\n";
10551070
}
10561071
next;
10571072
}
1058-
elsif ($other =~ /j/ && $line =~ /^j/) {
1059-
while (1) {
1060-
$ix++;
1061-
last if ($ix >= $num ||
1062-
!defined $hunk[$ix]{USE});
1073+
elsif ($line =~ /^j/) {
1074+
if ($other !~ /j/) {
1075+
print STDERR "No next hunk\n";
1076+
next;
10631077
}
1064-
next;
10651078
}
10661079
elsif ($other =~ /s/ && $line =~ /^s/) {
10671080
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});

0 commit comments

Comments
 (0)