add -p: fix counting empty context lines in edited patches
References: https://github.com/gitster/git/commit/f2cb01d35 https://public-inbox.org/git/20180601174644.13055-1-phillip.wood@talktalk.net/
This commit is contained in:
parent
9125e65273
commit
572ec3935e
@ -0,0 +1,99 @@
|
||||
From 5be233541a4fc2e395087fe51a30a3664165e8bc Mon Sep 17 00:00:00 2001
|
||||
From: Phillip Wood <phillip.wood@dunelm.org.uk>
|
||||
Date: Fri, 1 Jun 2018 18:46:44 +0100
|
||||
Subject: [PATCH] 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 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>
|
||||
---
|
||||
git-add--interactive.perl | 2 +-
|
||||
t/t3701-add-interactive.sh | 43 ++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 44 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
|
||||
index c1f52e457f..befbe8c749 100755
|
||||
--- a/git-add--interactive.perl
|
||||
+++ b/git-add--interactive.perl
|
||||
@@ -1055,7 +1055,7 @@ sub recount_edited_hunk {
|
||||
$o_cnt++;
|
||||
} elsif ($mode eq '+') {
|
||||
$n_cnt++;
|
||||
- } elsif ($mode eq ' ') {
|
||||
+ } elsif ($mode eq ' ' or $_ eq "\n") {
|
||||
$o_cnt++;
|
||||
$n_cnt++;
|
||||
}
|
||||
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
|
||||
index b170fb02b8..3e9139dca8 100755
|
||||
--- a/t/t3701-add-interactive.sh
|
||||
+++ b/t/t3701-add-interactive.sh
|
||||
@@ -175,6 +175,49 @@ test_expect_success 'real edit works' '
|
||||
diff_cmp expected output
|
||||
'
|
||||
|
||||
+test_expect_success 'setup file' '
|
||||
+ test_write_lines a "" b "" c >file &&
|
||||
+ git add file &&
|
||||
+ test_write_lines a "" d "" c >file
|
||||
+'
|
||||
+
|
||||
+test_expect_success 'setup patch' '
|
||||
+ SP=" " &&
|
||||
+ NULL="" &&
|
||||
+ cat >patch <<-EOF
|
||||
+ @@ -1,4 +1,4 @@
|
||||
+ a
|
||||
+ $NULL
|
||||
+ -b
|
||||
+ +f
|
||||
+ $SP
|
||||
+ c
|
||||
+ EOF
|
||||
+'
|
||||
+
|
||||
+test_expect_success 'setup expected' '
|
||||
+ cat >expected <<-EOF
|
||||
+ diff --git a/file b/file
|
||||
+ index b5dd6c9..f910ae9 100644
|
||||
+ --- a/file
|
||||
+ +++ b/file
|
||||
+ @@ -1,5 +1,5 @@
|
||||
+ a
|
||||
+ $SP
|
||||
+ -f
|
||||
+ +d
|
||||
+ $SP
|
||||
+ c
|
||||
+ EOF
|
||||
+'
|
||||
+
|
||||
+test_expect_success 'edit can strip spaces from empty context lines' '
|
||||
+ test_write_lines e n q | git add -p 2>error &&
|
||||
+ test_must_be_empty error &&
|
||||
+ git diff >output &&
|
||||
+ diff_cmp expected output
|
||||
+'
|
||||
+
|
||||
test_expect_success 'skip files similarly as commit -a' '
|
||||
git reset &&
|
||||
echo file >.gitignore &&
|
8
git.spec
8
git.spec
@ -83,7 +83,7 @@
|
||||
|
||||
Name: git
|
||||
Version: 2.18.0
|
||||
Release: 0.0%{?rcrev}%{?dist}
|
||||
Release: 0.0%{?rcrev}.1%{?dist}
|
||||
Summary: Fast Version Control System
|
||||
License: GPLv2
|
||||
URL: https://git-scm.com/
|
||||
@ -123,6 +123,9 @@ Patch1: git-cvsimport-Ignore-cvsps-2.2b1-Branches-output.patch
|
||||
# https://bugzilla.redhat.com/1581678
|
||||
# https://public-inbox.org/git/20180524062733.5412-1-newren@gmail.com/
|
||||
Patch2: 0001-rev-parse-check-lookup-ed-commit-references-for-NULL.patch
|
||||
# https://github.com/gitster/git/commit/f2cb01d35
|
||||
# https://public-inbox.org/git/20180601174644.13055-1-phillip.wood@talktalk.net/
|
||||
Patch3: 0001-add-p-fix-counting-empty-context-lines-in-edited-pat.patch
|
||||
|
||||
%if %{with docs}
|
||||
BuildRequires: asciidoc >= 8.4.1
|
||||
@ -871,6 +874,9 @@ make test || ./print-failed-test-output
|
||||
%{?with_docs:%{_pkgdocdir}/git-svn.html}
|
||||
|
||||
%changelog
|
||||
* Fri Jun 01 2018 Todd Zullinger <tmz@pobox.com> - 2.18.0-0.0.rc0.1
|
||||
- add -p: fix counting empty context lines in edited patches
|
||||
|
||||
* Wed May 30 2018 Todd Zullinger <tmz@pobox.com> - 2.18.0-0.0.rc0
|
||||
- Update to 2.18.0-rc0
|
||||
- Use new INSTALL_SYMLINKS setting
|
||||
|
Loading…
Reference in New Issue
Block a user