summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-03-08 00:36:00 -0800
committerJunio C Hamano <gitster@pobox.com>2010-03-08 00:36:00 -0800
commit919451330b55366ac207e575c1982bc8fa5220ed (patch)
tree5b11a7fb5c80483a5e29532ce42e72dd77f1d6e5 /git-add--interactive.perl
parent493e433277ee72b200e72f7a17e08266ed9497c5 (diff)
parente1327ed5fbaca0af44db89d60c33b641e2f21ee1 (diff)
downloadgit-919451330b55366ac207e575c1982bc8fa5220ed.tar.gz
Merge branch 'jk/maint-add--interactive-delete' into maint
* jk/maint-add--interactive-delete: add-interactive: fix bogus diff header line ordering
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl24
1 files changed, 23 insertions, 1 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index cd43c34912..21f1330a5b 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -957,6 +957,28 @@ sub coalesce_overlapping_hunks {
return @out;
}
+sub reassemble_patch {
+ my $head = shift;
+ my @patch;
+
+ # Include everything in the header except the beginning of the diff.
+ push @patch, (grep { !/^[-+]{3}/ } @$head);
+
+ # Then include any headers from the hunk lines, which must
+ # come before any actual hunk.
+ while (@_ && $_[0] !~ /^@/) {
+ push @patch, shift;
+ }
+
+ # Then begin the diff.
+ push @patch, grep { /^[-+]{3}/ } @$head;
+
+ # And then the actual hunks.
+ push @patch, @_;
+
+ return @patch;
+}
+
sub color_diff {
return map {
colored((/^@/ ? $fraginfo_color :
@@ -1453,7 +1475,7 @@ sub patch_update_file {
if (@result) {
my $fh;
- my @patch = (@{$head->{TEXT}}, @result);
+ my @patch = reassemble_patch($head->{TEXT}, @result);
my $apply_routine = $patch_mode_flavour{APPLY};
&$apply_routine(@patch);
refresh();