From 6adf8509afda865fea16366d80b2545ce2cef981 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 14 Dec 2016 12:48:12 +0300 Subject: [PATCH] merge: abort patch applying in read-only documents --- .../src/com/intellij/diff/tools/util/SimpleDiffPanel.java | 6 +++++- .../openapi/vcs/changes/patch/tool/ApplyPatchViewer.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/SimpleDiffPanel.java b/platform/diff-impl/src/com/intellij/diff/tools/util/SimpleDiffPanel.java index d2be844f7e66..14316f037f57 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/SimpleDiffPanel.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/SimpleDiffPanel.java @@ -35,7 +35,6 @@ public class SimpleDiffPanel extends DiffPanelBase { JPanel centerPanel = JBUI.Panels.simplePanel(editorPanel).addToTop(myNotificationsPanel); myContentPanel.add(centerPanel, GOOD_CONTENT); - myContentPanel.add(DiffUtil.createMessagePanel("Error"), ERROR_CONTENT); setCurrentCard(GOOD_CONTENT, false); } @@ -49,6 +48,11 @@ public class SimpleDiffPanel extends DiffPanelBase { } public void setErrorContent() { + setErrorContent("Error"); + } + + public void setErrorContent(@NotNull String message) { + myContentPanel.add(DiffUtil.createMessagePanel(message), ERROR_CONTENT); setCurrentCard(ERROR_CONTENT); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java index 45c04c14ccaf..d678ccec14ee 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/tool/ApplyPatchViewer.java @@ -49,6 +49,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.BooleanGetter; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch; import com.intellij.util.containers.ContainerUtil; import gnu.trove.TIntArrayList; @@ -285,10 +286,14 @@ class ApplyPatchViewer implements DataProvider, Disposable { protected void initPatchViewer() { final Document outputDocument = myResultEditor.getDocument(); - DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> { + boolean success = DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> { outputDocument.setText(myPatchRequest.getLocalContent()); if (!isReadOnly()) DiffUtil.putNonundoableOperation(myProject, outputDocument); }); + if (!success && !StringUtil.equals(outputDocument.getText(), myPatchRequest.getLocalContent())) { + myPanel.setErrorContent("Failed to display patch applier - local content was modified"); + return; + } PatchChangeBuilder builder = new PatchChangeBuilder();