From 1c922d637e7a3603dfb48c85c9d1c83906613779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Mon, 23 Sep 2019 17:25:01 +0200 Subject: [PATCH 1/2] Ignore '\ No newline at end of file' in diff --- .../scm/repository/spi/GitHunkParser.java | 4 ++- .../scm/repository/spi/GitHunkParserTest.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHunkParser.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHunkParser.java index b7594bb5d6..a65b9a6b02 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHunkParser.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitHunkParser.java @@ -79,7 +79,9 @@ final class GitHunkParser { ++oldLineCounter; break; default: - throw new IllegalStateException("cannot handle diff line: " + line); + if (!line.equals("\\ No newline at end of file")) { + throw new IllegalStateException("cannot handle diff line: " + line); + } } } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitHunkParserTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitHunkParserTest.java index a58fae644d..e3f09ce5ef 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitHunkParserTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitHunkParserTest.java @@ -68,6 +68,17 @@ class GitHunkParserTest { " a\n" + "~illegal line\n"; + private static final String NO_NEWLINE_DIFF = "diff --git a/.editorconfig b/.editorconfig\n" + + "index ea2a3ba..2f02f32 100644\n" + + "--- a/.editorconfig\n" + + "+++ b/.editorconfig\n" + + "@@ -10,3 +10,4 @@\n" + + " indent_style = space\n" + + " indent_size = 2\n" + + " charset = utf-8\n" + + "+added line\n" + + "\\ No newline at end of file\n"; + @Test void shouldParseHunks() { List hunks = new GitHunkParser().parse(DIFF_001); @@ -127,6 +138,27 @@ class GitHunkParserTest { assertThrows(IllegalStateException.class, () -> new GitHunkParser().parse(ILLEGAL_DIFF)); } + @Test + void shouldIgnoreNoNewlineLine() { + List hunks = new GitHunkParser().parse(NO_NEWLINE_DIFF); + + Hunk hunk = hunks.get(0); + + Iterator lines = hunk.iterator(); + + DiffLine line1 = lines.next(); + assertThat(line1.getOldLineNumber()).hasValue(10); + assertThat(line1.getNewLineNumber()).hasValue(10); + assertThat(line1.getContent()).isEqualTo("indent_style = space"); + + lines.next(); + lines.next(); + DiffLine lastLine = lines.next(); + assertThat(lastLine.getOldLineNumber()).isEmpty(); + assertThat(lastLine.getNewLineNumber()).hasValue(13); + assertThat(lastLine.getContent()).isEqualTo("added line"); + } + private void assertHunk(Hunk hunk, int oldStart, int oldLineCount, int newStart, int newLineCount) { assertThat(hunk.getOldStart()).isEqualTo(oldStart); assertThat(hunk.getOldLineCount()).isEqualTo(oldLineCount); From 885623d748ebbd4d5e6d58d81f0e4f3da33dda1c Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Wed, 25 Sep 2019 11:17:55 +0000 Subject: [PATCH 2/2] Close branch bugfix/ignore_no_newline_in_diff