summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorWilliam Pursell <bill.pursell@gmail.com>2008-12-04 10:22:40 +0000
committerJunio C Hamano <gitster@pobox.com>2008-12-04 17:59:45 -0800
commit070434d02b96ae0fac0a3364c202136f5eb5a7a9 (patch)
tree887ffeb9c2d9d4fd2c7e16dec96c00f04c9552c5 /git-add--interactive.perl
parent3f6aff68896f8490e101eb5c4ad8f0fa5b8b67bb (diff)
downloadgit-070434d02b96ae0fac0a3364c202136f5eb5a7a9.tar.gz
Add 'g' command to go to a hunk
When a minor change is made while the working directory is in a bit of a mess, it is somewhat difficult to wade through all of the hunks using git add --patch. This allows one to jump to the hunk that needs to be staged without having to respond 'n' to each preceding hunk. Signed-off-by: William Pursell <bill.pursell@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl26
1 files changed, 26 insertions, 0 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index eb11132b23..ca60356d00 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -800,6 +800,7 @@ y - stage this hunk
n - do not stage this hunk
a - stage this and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining hunks in the file
+g - select a hunk to go to
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
@@ -945,6 +946,9 @@ sub patch_update_file {
if ($ix < $num - 1) {
$other .= '/J';
}
+ if ($num > 1) {
+ $other .= '/g';
+ }
for ($i = 0; $i < $num; $i++) {
if (!defined $hunk[$i]{USE}) {
$undecided = 1;
@@ -978,6 +982,28 @@ sub patch_update_file {
}
next;
}
+ elsif ($other =~ /g/ && $line =~ /^g(.*)/) {
+ my $response = $1;
+ my $no = $ix > 10 ? $ix - 10 : 0;
+ while ($response eq '') {
+ my $extra = "";
+ $no = display_hunks(\@hunk, $no);
+ if ($no < $num) {
+ $extra = " (<ret> to see more)";
+ }
+ print "go to which hunk$extra? ";
+ $response = <STDIN>;
+ chomp $response;
+ }
+ if ($response !~ /^\s*\d+\s*$/) {
+ print STDERR "Invalid number: '$response'\n";
+ } elsif (0 < $response && $response <= $num) {
+ $ix = $response - 1;
+ } else {
+ print STDERR "Sorry, only $num hunks available.\n";
+ }
+ next;
+ }
elsif ($line =~ /^d/i) {
while ($ix < $num) {
if (!defined $hunk[$ix]{USE}) {