@matheusbsbs / matheus-bagliano / commits / ca7246864b
Fork 0

add--interactive: allow user to choose mode update

When using the 'p'atch command, instead of just throwing out any mode change, present it to the user in the same way that we show hunks. This way, the mode change can be staged independently from the changes to the contents. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 27, 2008 at 03:32 UTC ca7246864b43e9ea1922cc5386225ecd1b3bdd98
2 files changed +44 -1
git-add--interactive.perl
+33
@@ -814,6 +814,36 @@ sub patch_update_file {
814 for (@{$head->{DISPLAY}}) {
815 print;
816 }
817 +
818 + if (@{$mode->{TEXT}}) {
819 + while (1) {
820 + print @{$mode->{DISPLAY}};
821 + print colored $prompt_color,
822 + "Stage mode change [y/n/a/d/?]? ";
823 + my $line = <STDIN>;
824 + if ($line =~ /^y/i) {
825 + $mode->{USE} = 1;
826 + last;
827 + }
828 + elsif ($line =~ /^n/i) {
829 + $mode->{USE} = 0;
830 + last;
831 + }
832 + elsif ($line =~ /^a/i) {
833 + $_->{USE} = 1 foreach ($mode, @hunk);
834 + last;
835 + }
836 + elsif ($line =~ /^d/i) {
837 + $_->{USE} = 0 foreach ($mode, @hunk);
838 + last;
839 + }
840 + else {
841 + help_patch_cmd('');
842 + next;
843 + }
844 + }
845 + }
846 +
847 $num = scalar @hunk;
848 $ix = 0;
849
@@ -936,6 +966,9 @@ sub patch_update_file {
966
967 my $n_lofs = 0;
968 my @result = ();
969 + if ($mode->{USE}) {
970 + push @result, @{$mode->{TEXT}};
971 + }
972 for (@hunk) {
973 my $text = $_->{TEXT};
974 my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
t/t3701-add-interactive.sh
+11 -1
@@ -70,9 +70,19 @@ test_expect_success 'patch does not affect mode' '
70 git reset --hard &&
71 echo content >>file &&
72 chmod +x file &&
73 - printf "y\\n" | git add -p &&
73 + printf "n\\ny\\n" | git add -p &&
74 git show :file | grep content &&
75 git diff file | grep "new mode"
76 '
77
78 +test_expect_success 'stage mode but not hunk' '
79 + git reset --hard &&
80 + echo content >>file &&
81 + chmod +x file &&
82 + printf "y\\nn\\n" | git add -p &&
83 + git diff --cached file | grep "new mode" &&
84 + git diff file | grep "+content"
85 +'
86 +
87 +
88 test_done