add--interactive: quote commentChar regex

Since c9d961647 (i18n: add--interactive: mark edit_hunk_manually message for translation, 2016-12-14), when the user asks to edit a hunk manually, we respect core.commentChar in generating the edit instructions. However, when we then strip out comment lines, we use a simple regex like: /^$commentChar/ If your chosen comment character is a regex metacharacter, then that will behave in a confusing manner ("$", for instance, would only eliminate blank lines, not actual comment lines). We can fix that by telling perl not to respect metacharacters. Reported-by: Christian Rösch <christian@croesch.de> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 21, 2017 at 15:28 UTC d85d7ecb80ebc93f7380b4196c303756ee051668
2 files changed +9 -1
git-add--interactive.perl
+1 -1
@@ -1097,7 +1097,7 @@ EOF2
1097
1098 open $fh, '<', $hunkfile
1099 or die sprintf(__("failed to open hunk edit file for reading: %s"), $!);
1100 - my @newtext = grep { !/^$comment_line_char/ } <$fh>;
1100 + my @newtext = grep { !/^\Q$comment_line_char\E/ } <$fh>;
1101 close $fh;
1102 unlink $hunkfile;
1103
t/t3701-add-interactive.sh
+8
@@ -380,4 +380,12 @@ test_expect_success 'patch mode ignores unmerged entries' '
380 test_cmp expected diff
381 '
382
383 +test_expect_success 'hunk-editing handles custom comment char' '
384 + git reset --hard &&
385 + echo change >>file &&
386 + test_config core.commentChar "\$" &&
387 + echo e | GIT_EDITOR=true git add -p &&
388 + git diff --exit-code
389 +'
390 +
391 test_done