mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
Merge branch 'pw/add-p-single'
"git add -p" used to offer "/" (look for a matching hunk) as a choice, even there was only one hunk, which has been corrected. Also the single-key help is now given only for keys that are enabled (e.g. help for '/' won't be shown when there is only one hunk). * pw/add-p-single: add -p: improve error messages add -p: only bind search key if there's more than one hunk add -p: only display help for active keys
This commit is contained in:
commit
60f8b89518
|
@ -1184,7 +1184,13 @@ sub edit_hunk_loop {
|
||||||
);
|
);
|
||||||
|
|
||||||
sub help_patch_cmd {
|
sub help_patch_cmd {
|
||||||
print colored $help_color, __($help_patch_modes{$patch_mode}), "\n", __ <<EOF ;
|
local $_;
|
||||||
|
my $other = $_[0] . ",?";
|
||||||
|
print colored $help_color, __($help_patch_modes{$patch_mode}), "\n",
|
||||||
|
map { "$_\n" } grep {
|
||||||
|
my $c = quotemeta(substr($_, 0, 1));
|
||||||
|
$other =~ /,$c/
|
||||||
|
} split "\n", __ <<EOF ;
|
||||||
g - select a hunk to go to
|
g - select a hunk to go to
|
||||||
/ - search for a hunk matching the given regex
|
/ - search for a hunk matching the given regex
|
||||||
j - leave this hunk undecided, see next undecided hunk
|
j - leave this hunk undecided, see next undecided hunk
|
||||||
|
@ -1302,39 +1308,39 @@ sub display_hunks {
|
||||||
|
|
||||||
my %patch_update_prompt_modes = (
|
my %patch_update_prompt_modes = (
|
||||||
stage => {
|
stage => {
|
||||||
mode => N__("Stage mode change [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Stage mode change [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Stage deletion [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Stage deletion [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Stage this hunk [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Stage this hunk [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
stash => {
|
stash => {
|
||||||
mode => N__("Stash mode change [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Stash mode change [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Stash deletion [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Stash deletion [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Stash this hunk [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Stash this hunk [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
reset_head => {
|
reset_head => {
|
||||||
mode => N__("Unstage mode change [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Unstage mode change [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Unstage deletion [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Unstage deletion [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Unstage this hunk [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Unstage this hunk [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
reset_nothead => {
|
reset_nothead => {
|
||||||
mode => N__("Apply mode change to index [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Apply mode change to index [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Apply deletion to index [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Apply deletion to index [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Apply this hunk to index [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Apply this hunk to index [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
checkout_index => {
|
checkout_index => {
|
||||||
mode => N__("Discard mode change from worktree [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Discard mode change from worktree [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Discard deletion from worktree [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Discard deletion from worktree [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Discard this hunk from worktree [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Discard this hunk from worktree [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
checkout_head => {
|
checkout_head => {
|
||||||
mode => N__("Discard mode change from index and worktree [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Discard mode change from index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Discard deletion from index and worktree [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Discard deletion from index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Discard this hunk from index and worktree [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Discard this hunk from index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
checkout_nothead => {
|
checkout_nothead => {
|
||||||
mode => N__("Apply mode change to index and worktree [y,n,q,a,d,/%s,?]? "),
|
mode => N__("Apply mode change to index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
deletion => N__("Apply deletion to index and worktree [y,n,q,a,d,/%s,?]? "),
|
deletion => N__("Apply deletion to index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d,/%s,?]? "),
|
hunk => N__("Apply this hunk to index and worktree [y,n,q,a,d%s,?]? "),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1390,7 +1396,7 @@ sub patch_update_file {
|
||||||
$other .= ',J';
|
$other .= ',J';
|
||||||
}
|
}
|
||||||
if ($num > 1) {
|
if ($num > 1) {
|
||||||
$other .= ',g';
|
$other .= ',g,/';
|
||||||
}
|
}
|
||||||
for ($i = 0; $i < $num; $i++) {
|
for ($i = 0; $i < $num; $i++) {
|
||||||
if (!defined $hunk[$i]{USE}) {
|
if (!defined $hunk[$i]{USE}) {
|
||||||
|
@ -1431,8 +1437,12 @@ sub patch_update_file {
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
|
elsif ($line =~ /^g(.*)/) {
|
||||||
my $response = $1;
|
my $response = $1;
|
||||||
|
unless ($other =~ /g/) {
|
||||||
|
error_msg __("No other hunks to goto\n");
|
||||||
|
next;
|
||||||
|
}
|
||||||
my $no = $ix > 10 ? $ix - 10 : 0;
|
my $no = $ix > 10 ? $ix - 10 : 0;
|
||||||
while ($response eq '') {
|
while ($response eq '') {
|
||||||
$no = display_hunks(\@hunk, $no);
|
$no = display_hunks(\@hunk, $no);
|
||||||
|
@ -1478,6 +1488,10 @@ sub patch_update_file {
|
||||||
}
|
}
|
||||||
elsif ($line =~ m|^/(.*)|) {
|
elsif ($line =~ m|^/(.*)|) {
|
||||||
my $regex = $1;
|
my $regex = $1;
|
||||||
|
unless ($other =~ m|/|) {
|
||||||
|
error_msg __("No other hunks to search\n");
|
||||||
|
next;
|
||||||
|
}
|
||||||
if ($1 eq "") {
|
if ($1 eq "") {
|
||||||
print colored $prompt_color, __("search for regex? ");
|
print colored $prompt_color, __("search for regex? ");
|
||||||
$regex = <STDIN>;
|
$regex = <STDIN>;
|
||||||
|
@ -1546,7 +1560,11 @@ sub patch_update_file {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($other =~ /s/ && $line =~ /^s/) {
|
elsif ($line =~ /^s/) {
|
||||||
|
unless ($other =~ /s/) {
|
||||||
|
error_msg __("Sorry, cannot split this hunk\n");
|
||||||
|
next;
|
||||||
|
}
|
||||||
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
|
my @split = split_hunk($hunk[$ix]{TEXT}, $hunk[$ix]{DISPLAY});
|
||||||
if (1 < @split) {
|
if (1 < @split) {
|
||||||
print colored $header_color, sprintf(
|
print colored $header_color, sprintf(
|
||||||
|
@ -1558,7 +1576,11 @@ sub patch_update_file {
|
||||||
$num = scalar @hunk;
|
$num = scalar @hunk;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
elsif ($other =~ /e/ && $line =~ /^e/) {
|
elsif ($line =~ /^e/) {
|
||||||
|
unless ($other =~ /e/) {
|
||||||
|
error_msg __("Sorry, cannot edit this hunk\n");
|
||||||
|
next;
|
||||||
|
}
|
||||||
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
|
my $newhunk = edit_hunk_loop($head, \@hunk, $ix);
|
||||||
if (defined $newhunk) {
|
if (defined $newhunk) {
|
||||||
splice @hunk, $ix, 1, $newhunk;
|
splice @hunk, $ix, 1, $newhunk;
|
||||||
|
|
Loading…
Reference in a new issue