diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-04-09 00:29:24 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-04-09 00:29:24 -0700 |
commit | ce47dc077549d4952908a5377ab36474b2bd8446 (patch) | |
tree | 9b568c44db1488c2eb636bca33d0395f9545f25f | |
parent | ba9f517bdd2062d1d90d37e5b10d1688d48bc225 (diff) | |
parent | ca7246864b43e9ea1922cc5386225ecd1b3bdd98 (diff) | |
download | git-ce47dc077549d4952908a5377ab36474b2bd8446.tar.gz git-ce47dc077549d4952908a5377ab36474b2bd8446.tar.xz |
Merge branch 'jk/add-i-mode'
* jk/add-i-mode:
add--interactive: allow user to choose mode update
add--interactive: ignore mode change in 'p'atch command
-rwxr-xr-x | git-add--interactive.perl | 49 | ||||
-rwxr-xr-x | t/t3701-add-interactive.sh | 19 |
2 files changed, 68 insertions, 0 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl index a0a81f134..903953e68 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -550,6 +550,21 @@ sub parse_diff { 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) = @_; @@ -795,9 +810,40 @@ sub patch_update_file { my ($ix, $num); my $path = shift; my ($head, @hunk) = parse_diff($path); + ($head, my $mode) = parse_diff_header($head); for (@{$head->{DISPLAY}}) { print; } + + if (@{$mode->{TEXT}}) { + while (1) { + print @{$mode->{DISPLAY}}; + print colored $prompt_color, + "Stage mode change [y/n/a/d/?]? "; + my $line = <STDIN>; + if ($line =~ /^y/i) { + $mode->{USE} = 1; + last; + } + elsif ($line =~ /^n/i) { + $mode->{USE} = 0; + last; + } + elsif ($line =~ /^a/i) { + $_->{USE} = 1 foreach ($mode, @hunk); + last; + } + elsif ($line =~ /^d/i) { + $_->{USE} = 0 foreach ($mode, @hunk); + last; + } + else { + help_patch_cmd(''); + next; + } + } + } + $num = scalar @hunk; $ix = 0; @@ -920,6 +966,9 @@ sub patch_update_file { my $n_lofs = 0; my @result = (); + if ($mode->{USE}) { + push @result, @{$mode->{TEXT}}; + } for (@hunk) { my $text = $_->{TEXT}; my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) = diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 77c90f6fa..f15be93e7 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -66,4 +66,23 @@ test_expect_success 'revert works (commit)' ' grep "unchanged *+3/-0 file" output ' +test_expect_success 'patch does not affect mode' ' + git reset --hard && + echo content >>file && + chmod +x file && + printf "n\\ny\\n" | git add -p && + git show :file | grep content && + git diff file | grep "new mode" +' + +test_expect_success 'stage mode but not hunk' ' + git reset --hard && + echo content >>file && + chmod +x file && + printf "y\\nn\\n" | git add -p && + git diff --cached file | grep "new mode" && + git diff file | grep "+content" +' + + test_done |