Skip to content

Commit 54e6ce5

Browse files
committed
Merge branch 'jk/add-p-commentchar-fix'
"git add -p" were updated in 2.12 timeframe to cope with custom core.commentchar but the implementation was buggy and a metacharacter like $ and * did not work. * jk/add-p-commentchar-fix: add--interactive: quote commentChar regex add--interactive: handle EOF in prompt_yesno
2 parents e25a767 + d85d7ec commit 54e6ce5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

git-add--interactive.perl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ sub edit_hunk_manually {
10811081

10821082
open $fh, '<', $hunkfile
10831083
or die sprintf(__("failed to open hunk edit file for reading: %s"), $!);
1084-
my @newtext = grep { !/^$comment_line_char/ } <$fh>;
1084+
my @newtext = grep { !/^\Q$comment_line_char\E/ } <$fh>;
10851085
close $fh;
10861086
unlink $hunkfile;
10871087

@@ -1136,6 +1136,7 @@ sub prompt_yesno {
11361136
while (1) {
11371137
print colored $prompt_color, $prompt;
11381138
my $line = prompt_single_character;
1139+
return undef unless defined $line;
11391140
return 0 if $line =~ /^n/i;
11401141
return 1 if $line =~ /^y/i;
11411142
}

t/t3701-add-interactive.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,12 @@ test_expect_success 'add -p does not expand argument lists' '
477477
! grep not-changed trace.out
478478
'
479479

480+
test_expect_success 'hunk-editing handles custom comment char' '
481+
git reset --hard &&
482+
echo change >>file &&
483+
test_config core.commentChar "\$" &&
484+
echo e | GIT_EDITOR=true git add -p &&
485+
git diff --exit-code
486+
'
487+
480488
test_done

0 commit comments

Comments
 (0)