File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,8 @@ deletion labelled with a number and you will be prompted to enter which
342
342
lines you wish to select. Individual line numbers should be separated by
343
343
a space or comma, to specify a range of lines use a dash between
344
344
them. If the upper bound of a range of lines is omitted it defaults to
345
- the last line.
345
+ the last line. To invert the selection prefix it with "-" so "-3-5,8"
346
+ will select everything except lines 3, 4, 5 and 8.
346
347
+
347
348
After deciding the fate for all hunks, if there is any hunk
348
349
that was chosen, the index is updated with the selected hunks.
Original file line number Diff line number Diff line change @@ -1085,9 +1085,21 @@ sub check_hunk_label {
1085
1085
sub parse_hunk_selection {
1086
1086
local $_ ;
1087
1087
my ($hunk , $line ) = @_ ;
1088
- my $max_label = $hunk -> {MAX_LABEL };
1088
+ my ( $max_label , $invert ) = ( $hunk -> {MAX_LABEL }, undef ) ;
1089
1089
my @selected = (0) x ($max_label + 1);
1090
1090
my @fields = split (/ [,\s ]+/ , $line );
1091
+ if ($fields [0] =~ / ^-(.*)/ ) {
1092
+ $invert = 1;
1093
+ if ($1 ne ' ' ) {
1094
+ $fields [0] = $1 ;
1095
+ } else {
1096
+ shift @fields ;
1097
+ unless (@fields ) {
1098
+ error_msg __(" no lines to invert\n " );
1099
+ return undef ;
1100
+ }
1101
+ }
1102
+ }
1091
1103
for (@fields ) {
1092
1104
if (my ($lo , $hi ) = /^([0-9]+)-([0-9]*)$/ ) {
1093
1105
if ($hi eq ' ' ) {
@@ -1107,6 +1119,9 @@ sub parse_hunk_selection {
1107
1119
return undef ;
1108
1120
}
1109
1121
}
1122
+ if ($invert ) {
1123
+ @selected = map { !$_ } @selected ;
1124
+ }
1110
1125
return \@selected ;
1111
1126
}
1112
1127
Original file line number Diff line number Diff line change @@ -410,7 +410,7 @@ test_expect_success 'setup expected diff' '
410
410
'
411
411
412
412
test_expect_success ' can reset individual lines of patch' '
413
- printf "%s\n" l 2 |
413
+ printf "%s\n" l "-1 3" |
414
414
EDITOR=: git reset -p 2>error &&
415
415
test_must_be_empty error &&
416
416
git diff --cached HEAD >actual &&
You can’t perform that action at this time.
0 commit comments