diff --git a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java index 30f5a59f521c..440cef8bce68 100644 --- a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java +++ b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java @@ -179,13 +179,32 @@ public class TextPatchBuilder { } } } + + checkPathEndLine(patch, c.getAfter()); } else if (! beforeRevision.getPath().equals(afterRevision.getPath())) { - result.add(buildMovedFile(myBasePath, beforeRevision, afterRevision, beforeLines)); + final TextFilePatch movedPatch = buildMovedFile(myBasePath, beforeRevision, afterRevision, beforeLines); + checkPathEndLine(movedPatch, c.getAfter()); + result.add(movedPatch); } } return result; } + private void checkPathEndLine(TextFilePatch filePatch, final AirContentRevision cr) throws VcsException { + if (cr == null) return; + if (filePatch.isDeletedFile() || filePatch.getAfterName() == null) return; + final List hunks = filePatch.getHunks(); + if (hunks.isEmpty()) return; + final PatchHunk hunk = hunks.get(hunks.size() - 1); + final List lines = hunk.getLines(); + if (lines.isEmpty()) return; + final String contentAsString = cr.getContentAsString(); + if (contentAsString == null) return; + if (! contentAsString.endsWith("\n")) { + lines.get(lines.size() - 1).setSuppressNewLine(true); + } + } + private static String[] tokenize(String text) { return text.length() == 0 ? new String[]{text} : new LineTokenizer(text).execute(); }