summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2018-06-11 09:46:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-11 16:45:19 (GMT)
commitf4d35a6b49621348c73222e7017a434551799308 (patch)
tree6e837e8aba490dfebfdce61817e1c0b93ed746ed /git-add--interactive.perl
parent3a8522f41ff45b16e06888d2b164252c9aeeaa03 (diff)
downloadgit-f4d35a6b49621348c73222e7017a434551799308.zip
git-f4d35a6b49621348c73222e7017a434551799308.tar.gz
git-f4d35a6b49621348c73222e7017a434551799308.tar.bz2
add -p: fix counting empty context lines in edited patches
recount_edited_hunk() introduced in commit 2b8ea7f3c7 ("add -p: calculate offset delta for edited patches", 2018-03-05) required all context lines to start with a space, empty lines are not counted. This was intended to avoid any recounting problems if the user had introduced empty lines at the end when editing the patch. However this introduced a regression into 'git add -p' as it seems it is common for editors to strip the trailing whitespace from empty context lines when patches are edited thereby introducing empty lines that should be counted. 'git apply' knows how to deal with such empty lines and POSIX states that whether or not there is an space on an empty context line is implementation defined [1]. Fix the regression by counting lines that consist solely of a newline as well as lines starting with a space as context lines and add a test to prevent future regressions. [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html Reported-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net> Reported-by: Oliver Joseph Ash <oliverjash@gmail.com> Reported-by: Jeff Felchner <jfelchner1@gmail.com> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl2
1 files changed, 1 insertions, 1 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index ab022ec..8361ef4 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1047,7 +1047,7 @@ sub recount_edited_hunk {
$o_cnt++;
} elsif ($mode eq '+') {
$n_cnt++;
- } elsif ($mode eq ' ') {
+ } elsif ($mode eq ' ' or $mode eq "\n") {
$o_cnt++;
$n_cnt++;
}