]> granicus.if.org Git - git/commitdiff
add--interactive: quote commentChar regex
authorJeff King <peff@peff.net>
Wed, 21 Jun 2017 19:28:59 +0000 (15:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Jun 2017 21:06:20 +0000 (14:06 -0700)
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>
git-add--interactive.perl
t/t3701-add-interactive.sh

index 7c953247379c77bf49fd6806648bfee99c134471..395dd5eb4b83377f59b486f7b483bf2103efcdec 100755 (executable)
@@ -1097,7 +1097,7 @@ EOF2
 
        open $fh, '<', $hunkfile
                or die sprintf(__("failed to open hunk edit file for reading: %s"), $!);
-       my @newtext = grep { !/^$comment_line_char/ } <$fh>;
+       my @newtext = grep { !/^\Q$comment_line_char\E/ } <$fh>;
        close $fh;
        unlink $hunkfile;
 
index deae948c76bd12f9b3ef6b54568717b21d641d8a..2bfd41f06e4435607760dbe6d78ec72633e46aba 100755 (executable)
@@ -380,4 +380,12 @@ test_expect_success 'patch mode ignores unmerged entries' '
        test_cmp expected diff
 '
 
+test_expect_success 'hunk-editing handles custom comment char' '
+       git reset --hard &&
+       echo change >>file &&
+       test_config core.commentChar "\$" &&
+       echo e | GIT_EDITOR=true git add -p &&
+       git diff --exit-code
+'
+
 test_done