If you press "l" then the hunk will be reprinted with each insertion or
deletion labelled with a number and you will be prompted to enter which
lines you wish to select. Individual line numbers should be separated by
-a space or comma, to specify a range of lines use a dash between
-them. If the upper bound of a range of lines is omitted it defaults to
-the last line. To invert the selection prefix it with "-" so "-3-5,8"
-will select everything except lines 3, 4, 5 and 8.
+a space or comma (these can be omitted if there are fewer than ten
+labelled lines), to specify a range of lines use a dash between them. If
+the upper bound of a range of lines is omitted it defaults to the last
+line. To invert the selection prefix it with "-" so "-3-5,8" will select
+everything except lines 3, 4, 5 and 8.
+
After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.
return 1;
}
+sub split_hunk_selection {
+ local $_;
+ my @fields = @_;
+ my @ret;
+ for (@fields) {
+ while ($_ ne '') {
+ if (/^[0-9]-$/) {
+ push @ret, $_;
+ last;
+ } elsif (/^([0-9](?:-[0-9])?)(.*)/) {
+ push @ret, $1;
+ $_ = $2;
+ } else {
+ error_msg sprintf
+ __("invalid hunk line '%s'\n"),
+ substr($_, 0, 1);
+ return ();
+ }
+ }
+ }
+ return @ret;
+}
+
sub parse_hunk_selection {
local $_;
my ($hunk, $line) = @_;
}
}
}
+ if ($max_label < 10) {
+ @fields = split_hunk_selection(@fields) or return undef;
+ }
for (@fields) {
if (my ($lo, $hi) = /^([0-9]+)-([0-9]*)$/) {
if ($hi eq '') {
'
test_expect_success 'can reset individual lines of patch' '
- printf "%s\n" l "-1 3" |
+ printf "%s\n" l -13 |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&