Skip to content

Commit 88f6ffc

Browse files
phillipwoodgitster
authored andcommitted
add -p: only bind search key if there's more than one hunk
If there is only a single hunk then disable searching as there is nothing to search for. Also print a specific error message if the user tries to search with '/' when there's only a single hunk rather than just listing the key bindings. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 01a6966 commit 88f6ffc

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

git-add--interactive.perl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ sub edit_hunk_loop {
11851185

11861186
sub help_patch_cmd {
11871187
local $_;
1188-
my $other = $_[0] . ",/,?";
1188+
my $other = $_[0] . ",?";
11891189
print colored $help_color, __($help_patch_modes{$patch_mode}), "\n",
11901190
map { "$_\n" } grep {
11911191
my $c = quotemeta(substr($_, 0, 1));
@@ -1308,39 +1308,39 @@ sub display_hunks {
13081308

13091309
my %patch_update_prompt_modes = (
13101310
stage => {
1311-
mode => N__("Stage mode change [y,n,q,a,d,/%s,?]? "),
1312-
deletion => N__("Stage deletion [y,n,q,a,d,/%s,?]? "),
1313-
hunk => N__("Stage this hunk [y,n,q,a,d,/%s,?]? "),
1311+
mode => N__("Stage mode change [y,n,q,a,d%s,?]? "),
1312+
deletion => N__("Stage deletion [y,n,q,a,d%s,?]? "),
1313+
hunk => N__("Stage this hunk [y,n,q,a,d%s,?]? "),
13141314
},
13151315
stash => {
1316-
mode => N__("Stash mode change [y,n,q,a,d,/%s,?]? "),
1317-
deletion => N__("Stash deletion [y,n,q,a,d,/%s,?]? "),
1318-
hunk => N__("Stash this hunk [y,n,q,a,d,/%s,?]? "),
1316+
mode => N__("Stash mode change [y,n,q,a,d%s,?]? "),
1317+
deletion => N__("Stash deletion [y,n,q,a,d%s,?]? "),
1318+
hunk => N__("Stash this hunk [y,n,q,a,d%s,?]? "),
13191319
},
13201320
reset_head => {
1321-
mode => N__("Unstage mode change [y,n,q,a,d,/%s,?]? "),
1322-
deletion => N__("Unstage deletion [y,n,q,a,d,/%s,?]? "),
1323-
hunk => N__("Unstage this hunk [y,n,q,a,d,/%s,?]? "),
1321+
mode => N__("Unstage mode change [y,n,q,a,d%s,?]? "),
1322+
deletion => N__("Unstage deletion [y,n,q,a,d%s,?]? "),
1323+
hunk => N__("Unstage this hunk [y,n,q,a,d%s,?]? "),
13241324
},
13251325
reset_nothead => {
1326-
mode => N__("Apply mode change to index [y,n,q,a,d,/%s,?]? "),
1327-
deletion => N__("Apply deletion to index [y,n,q,a,d,/%s,?]? "),
1328-
hunk => N__("Apply this hunk to index [y,n,q,a,d,/%s,?]? "),
1326+
mode => N__("Apply mode change to index [y,n,q,a,d%s,?]? "),
1327+
deletion => N__("Apply deletion to index [y,n,q,a,d%s,?]? "),
1328+
hunk => N__("Apply this hunk to index [y,n,q,a,d%s,?]? "),
13291329
},
13301330
checkout_index => {
1331-
mode => N__("Discard mode change from worktree [y,n,q,a,d,/%s,?]? "),
1332-
deletion => N__("Discard deletion from worktree [y,n,q,a,d,/%s,?]? "),
1333-
hunk => N__("Discard this hunk from worktree [y,n,q,a,d,/%s,?]? "),
1331+
mode => N__("Discard mode change from worktree [y,n,q,a,d%s,?]? "),
1332+
deletion => N__("Discard deletion from worktree [y,n,q,a,d%s,?]? "),
1333+
hunk => N__("Discard this hunk from worktree [y,n,q,a,d%s,?]? "),
13341334
},
13351335
checkout_head => {
1336-
mode => N__("Discard mode change from index and worktree [y,n,q,a,d,/%s,?]? "),
1337-
deletion => N__("Discard deletion from index and worktree [y,n,q,a,d,/%s,?]? "),
1338-
hunk => N__("Discard this hunk from index and worktree [y,n,q,a,d,/%s,?]? "),
1336+
mode => N__("Discard mode change from index and worktree [y,n,q,a,d%s,?]? "),
1337+
deletion => N__("Discard deletion from index and worktree [y,n,q,a,d%s,?]? "),
1338+
hunk => N__("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? "),
13391339
},
13401340
checkout_nothead => {
1341-
mode => N__("Apply mode change to index and worktree [y,n,q,a,d,/%s,?]? "),
1342-
deletion => N__("Apply deletion to index and worktree [y,n,q,a,d,/%s,?]? "),
1343-
hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d,/%s,?]? "),
1341+
mode => N__("Apply mode change to index and worktree [y,n,q,a,d%s,?]? "),
1342+
deletion => N__("Apply deletion to index and worktree [y,n,q,a,d%s,?]? "),
1343+
hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? "),
13441344
},
13451345
);
13461346

@@ -1396,7 +1396,7 @@ sub patch_update_file {
13961396
$other .= ',J';
13971397
}
13981398
if ($num > 1) {
1399-
$other .= ',g';
1399+
$other .= ',g,/';
14001400
}
14011401
for ($i = 0; $i < $num; $i++) {
14021402
if (!defined $hunk[$i]{USE}) {
@@ -1484,6 +1484,10 @@ sub patch_update_file {
14841484
}
14851485
elsif ($line =~ m|^/(.*)|) {
14861486
my $regex = $1;
1487+
unless ($other =~ m|/|) {
1488+
error_msg __("No other hunks to search\n");
1489+
next;
1490+
}
14871491
if ($1 eq "") {
14881492
print colored $prompt_color, __("search for regex? ");
14891493
$regex = <STDIN>;

0 commit comments

Comments
 (0)