Skip to content

Commit

Permalink
add--interactive: allow user to choose mode update
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Mar 27, 2008
1 parent b717a62 commit ca72468
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
33 changes: 33 additions & 0 deletions git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,36 @@ sub patch_update_file {
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;

Expand Down Expand Up @@ -936,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) =
Expand Down
12 changes: 11 additions & 1 deletion t/t3701-add-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,19 @@ test_expect_success 'patch does not affect mode' '
git reset --hard &&
echo content >>file &&
chmod +x file &&
printf "y\\n" | git add -p &&
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

0 comments on commit ca72468

Please sign in to comment.