From f16ef7bd4c37fba8c030b87610f646a1fce5d52d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 15 Feb 2018 01:29:27 +0100 Subject: [PATCH 1/2] apply: demonstrate a problem applying svn diffs Subversion generates diffs that contain funny ---/+++ lines containing more than just the file names. Example: --- a/trunk/README (revision 4711) +++ /dev/null (nonexistent) Let's add a test case demonstrating that apply cannot handle the /dev/null line (although it can handle the trunk/README line just fine). Reported in https://github.com/git-for-windows/git/issues/1489 Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t4135-apply-weird-filenames.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh index 27cb0009fb..b14b808578 100755 --- a/t/t4135-apply-weird-filenames.sh +++ b/t/t4135-apply-weird-filenames.sh @@ -89,4 +89,21 @@ test_expect_success 'traditional, whitespace-damaged, colon in timezone' ' test_cmp expected "post image.txt" ' +cat >diff-from-svn <<\EOF +Index: Makefile +=================================================================== +diff --git a/branches/Makefile +deleted file mode 100644 +--- a/branches/Makefile (revision 13) ++++ /dev/null (nonexistent) +@@ +1 0,0 @@ +- +EOF + +test_expect_failure 'apply handles a diff generated by Subversion' ' + >Makefile && + git apply -p2 diff-from-svn && + test_path_is_missing Makefile +' + test_done From e454ad4becff73588b1b3cc24dba3a0e740c7f7c Mon Sep 17 00:00:00 2001 From: Tatyana Krasnukha Date: Thu, 15 Feb 2018 01:29:34 +0100 Subject: [PATCH 2/2] apply: handle Subversion diffs with /dev/null gracefully Subversion generates diffs that can contain lines like this one: --- /dev/null (nonexistent) Let's teach Git's apply machinery to handle such a line gracefully. This fixes https://github.com/git-for-windows/git/isues/1489 Signed-off-by: Tatyana Krasnukha Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- apply.c | 2 +- t/t4135-apply-weird-filenames.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apply.c b/apply.c index 0c7b25989c..3aadbae305 100644 --- a/apply.c +++ b/apply.c @@ -975,7 +975,7 @@ static int gitdiff_verify_name(struct apply_state *state, } free(another); } else { - if (!starts_with(line, "/dev/null\n")) + if (!is_dev_null(line)) return error(_("git apply: bad git-diff - expected /dev/null on line %d"), state->linenr); } diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh index b14b808578..c7c688fcc4 100755 --- a/t/t4135-apply-weird-filenames.sh +++ b/t/t4135-apply-weird-filenames.sh @@ -100,7 +100,7 @@ deleted file mode 100644 - EOF -test_expect_failure 'apply handles a diff generated by Subversion' ' +test_expect_success 'apply handles a diff generated by Subversion' ' >Makefile && git apply -p2 diff-from-svn && test_path_is_missing Makefile