diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b0223c3..e6d73a0 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -553,7 +553,7 @@ sub parse_diff {
for (my $i = 0; $i < @diff; $i++) {
if ($diff[$i] =~ /^@@ /) {
- push @hunk, { TEXT => [], DISPLAY => [] };
+ push @hunk, { TEXT => [], DISPLAY => [], SUMMARY => $diff[$i] };
}
push @{$hunk[-1]{TEXT}}, $diff[$i];
push @{$hunk[-1]{DISPLAY}},@@ -685,6 +685,7 @@ sub split_hunk {
(($n_cnt != 1) ? ",$n_cnt" : '') .
" @@\n");
my $display_head = $head;
+ $hunk->{SUMMARY} = $head;
unshift @{$hunk->{TEXT}}, $head;
if ($diff_use_color) {
$display_head = colored($fraginfo_color, $head);@@ -783,6 +784,7 @@ sub edit_hunk_loop {
$newhunk,
@{$hunk}[$ix+1..$#{$hunk}])) {
$newhunk->{DISPLAY} = [color_diff(@{$text})];
+ $newhunk->{SUMMARY} = $$text[0];
return $newhunk;
}
else {@@ -799,6 +801,7 @@ sub help_patch_cmd {
y - stage this hunk
n - do not stage this hunk
a - stage this and all the remaining hunks in the file
+g - select a hunk to jump to
d - do not stage this hunk nor any of the remaining hunks in the file
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk@@ -836,6 +839,27 @@ sub patch_update_cmd {
}
}
+sub select_new_hunk {
+ my $ri = shift;
+ my @hunk = @_;
+ my ($i, $response);
+ print " '+' stage, '-' don't stage\n";
+ for ( $i = 0; $i < @hunk; $i++ ) {
+ my $status = " ";
+ if( defined $hunk[$i]{USE} ) {
+ $status = $hunk[$i]{USE} ? "+" : "-";
+ }
+ printf "%s%3d: %s",
+ $status,
+ $i + 1,
+ $hunk[$i]{SUMMARY};
+ }
+ printf "goto which hunk? ";
+ $response = <STDIN>;
+ chomp $response;
+ $$ri = $response - 1;
+}
+
sub patch_update_file {
my ($ix, $num);
my $path = shift;@@ -919,7 +943,7 @@ sub patch_update_file {
for (@{$hunk[$ix]{DISPLAY}}) {
print;
}
- print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? ";
+ print colored $prompt_color, "Stage this hunk [y/n/a/d/g$other/?]? ";
my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {@@ -937,6 +961,16 @@ sub patch_update_file {
}
next;
}
+ elsif ($line =~ /^g/) {
+ chomp ($line);
+ if ($line =~ /^g$/) {
+ select_new_hunk (\$ix, @hunk);
+ }
+ else {
+ $ix = (substr $line, 1) - 1;
+ }
+ next;
+ }
elsif ($line =~ /^d/i) {
while ($ix < $num) {
if (!defined $hunk[$ix]{USE}) {
--
William Pursell