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.
+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.
sub parse_hunk_selection {
local $_;
my ($hunk, $line) = @_;
- my $max_label = $hunk->{MAX_LABEL};
+ my ($max_label, $invert) = ($hunk->{MAX_LABEL}, undef);
my @selected = (0) x ($max_label + 1);
my @fields = split(/[,\s]+/, $line);
+ if ($fields[0] =~ /^-(.*)/) {
+ $invert = 1;
+ if ($1 ne '') {
+ $fields[0] = $1;
+ } else {
+ shift @fields;
+ unless (@fields) {
+ error_msg __("no lines to invert\n");
+ return undef;
+ }
+ }
+ }
for (@fields) {
if (my ($lo, $hi) = /^([0-9]+)-([0-9]*)$/) {
if ($hi eq '') {
return undef;
}
}
+ if ($invert) {
+ @selected = map { !$_ } @selected;
+ }
return \@selected;
}
'
test_expect_success 'can reset individual lines of patch' '
- printf "%s\n" l 2 |
+ printf "%s\n" l "-1 3" |
EDITOR=: git reset -p 2>error &&
test_must_be_empty error &&
git diff --cached HEAD >actual &&