summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1768905)
raw | patch | inline | side by side (parent: 1768905)
author | Jeff King <peff@peff.net> | |
Thu, 27 Mar 2008 07:30:43 +0000 (03:30 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 27 Mar 2008 20:54:56 +0000 (13:54 -0700) |
When a path is examined in the patch subcommand, any mode changes in
the file are given to use in the diff header by git-diff. If no hunks
are staged, then we throw out that header and do not touch the
path. But if _any_ hunks are staged, we use the header, and the mode
is changed together with the contents.
Since the 'p'atch command should just be dealing with hunks that are
shown to the user, it makes sense to just ignore mode changes
entirely. We do squirrel away the mode, though, since the next patch
will allow users to select the mode update separately.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
the file are given to use in the diff header by git-diff. If no hunks
are staged, then we throw out that header and do not touch the
path. But if _any_ hunks are staged, we use the header, and the mode
is changed together with the contents.
Since the 'p'atch command should just be dealing with hunks that are
shown to the user, it makes sense to just ignore mode changes
entirely. We do squirrel away the mode, though, since the next patch
will allow users to select the mode update separately.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-add--interactive.perl | patch | blob | history | |
t/t3701-add-interactive.sh | patch | blob | history |
index a0a81f134a6288dfc1d87431698f29597ed5e488..5cdda29c548fd8aa776622b6a698516d8ca386e4 100755 (executable)
return @hunk;
}
+sub parse_diff_header {
+ my $src = shift;
+
+ my $head = { TEXT => [], DISPLAY => [] };
+ my $mode = { TEXT => [], DISPLAY => [] };
+
+ for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
+ my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
+ $mode : $head;
+ push @{$dest->{TEXT}}, $src->{TEXT}->[$i];
+ push @{$dest->{DISPLAY}}, $src->{DISPLAY}->[$i];
+ }
+ return ($head, $mode);
+}
+
sub hunk_splittable {
my ($text) = @_;
my ($ix, $num);
my $path = shift;
my ($head, @hunk) = parse_diff($path);
+ ($head, my $mode) = parse_diff_header($head);
for (@{$head->{DISPLAY}}) {
print;
}
index 77c90f6fa002ce00c3ffb30d0b79adaff46b3caa..d920d06d5a8e1f5c09f2f0a2d5a77da1b59cdccf 100755 (executable)
grep "unchanged *+3/-0 file" output
'
+test_expect_success 'patch does not affect mode' '
+ git reset --hard &&
+ echo content >>file &&
+ chmod +x file &&
+ printf "y\\n" | git add -p &&
+ git show :file | grep content &&
+ git diff file | grep "new mode"
+'
+
test_done