Skip to content

Commit d85d7ec

Browse files
peffgitster
authored andcommitted
add--interactive: quote commentChar regex
Since c9d9616 (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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5addcf commit d85d7ec

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

git-add--interactive.perl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ sub edit_hunk_manually {
10971097

10981098
open $fh, '<', $hunkfile
10991099
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>;
11011101
close $fh;
11021102
unlink $hunkfile;
11031103

t/t3701-add-interactive.sh

+8
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,12 @@ test_expect_success 'patch mode ignores unmerged entries' '
380380
test_cmp expected diff
381381
'
382382

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+
383391
test_done

0 commit comments

Comments
 (0)