diff --git a/platform/lvcs-api/src/com/intellij/history/Label.java b/platform/lvcs-api/src/com/intellij/history/Label.java index 7ae95c27be27..8abe4f7fb9c7 100644 --- a/platform/lvcs-api/src/com/intellij/history/Label.java +++ b/platform/lvcs-api/src/com/intellij/history/Label.java @@ -32,7 +32,7 @@ public interface Label { } }; - void revert(@NotNull Project project, @NotNull VirtualFile file); + void revert(@NotNull Project project, @NotNull VirtualFile file) throws LocalHistoryException; ByteContent getByteContent(String path); } diff --git a/platform/lvcs-api/src/com/intellij/history/LocalHistoryException.java b/platform/lvcs-api/src/com/intellij/history/LocalHistoryException.java new file mode 100644 index 000000000000..d9f188f7091b --- /dev/null +++ b/platform/lvcs-api/src/com/intellij/history/LocalHistoryException.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.history; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + + +/** + * Wrapper for any exception occurred during local history actions and processes + */ +public class LocalHistoryException extends Exception { + public LocalHistoryException(@NotNull String message) { + super(message); + } + + public LocalHistoryException(@NotNull String message, @Nullable Throwable cause) { + super(message, cause); + } +} diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java index b1f21d89c76c..20bcfb645d36 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java @@ -23,9 +23,6 @@ import com.intellij.history.integration.ui.models.DirectoryHistoryDialogModel; import com.intellij.history.integration.ui.models.EntireFileHistoryDialogModel; import com.intellij.history.integration.ui.models.HistoryDialogModel; import com.intellij.history.utils.LocalHistoryLog; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.command.CommandProcessor; @@ -193,7 +190,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone private Label label(final LabelImpl impl) { return new Label() { @Override - public void revert(@NotNull Project project, @NotNull VirtualFile file) { + public void revert(@NotNull Project project, @NotNull VirtualFile file) throws LocalHistoryException { revertToLabel(project, file, impl); } @@ -249,16 +246,13 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone return myGateway; } - private void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull LabelImpl impl) { + private void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull LabelImpl impl) throws LocalHistoryException{ HistoryDialogModel dirHistoryModel = f.isDirectory() ? new DirectoryHistoryDialogModel(project, myGateway, myVcs, f) : new EntireFileHistoryDialogModel(project, myGateway, myVcs, f); int leftRev = findRevisionIndexToRevert(dirHistoryModel, impl); if (leftRev < 0) { - notifyUser(project, - String.format("Couldn't find label revision. Try to use local history dialog for %s and perform revert manually.", - f.getName())); - return; + throw new LocalHistoryException("Couldn't find label revision"); } if (leftRev == 0) return; // we shouldn't revert because no changes found to revert; try { @@ -266,12 +260,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone dirHistoryModel.createReverter().revert(); } catch (IOException e) { - LocalHistoryLog.LOG.error(String.format("Couldn't revert %s to local history label.", f.getName()), e); + throw new LocalHistoryException(String.format("Couldn't revert %s to local history label.", f.getName()), e); } } - - private static void notifyUser(@NotNull Project project, @NotNull String message) { - new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Can't rollback some changes", message, - NotificationType.ERROR).notify(project); - } } diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java index 645d0ce5ddc0..d3422e36e2c0 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java @@ -17,11 +17,10 @@ package com.intellij.history.integration.revertion; import com.intellij.history.Label; import com.intellij.history.LocalHistory; +import com.intellij.history.LocalHistoryException; import com.intellij.history.integration.IntegrationTestCase; import com.intellij.openapi.vfs.VirtualFile; -import java.io.IOException; - public class HistoryReverterToLabelTest extends IntegrationTestCase { public void testFileCreation() throws Exception { @@ -33,7 +32,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { assertNotNull(myRoot.findChild("first.txt")); } - private void revertToLabel(Label testLabel, VirtualFile root) { + private void revertToLabel(Label testLabel, VirtualFile root) throws LocalHistoryException { testLabel.revert(myProject, root); } @@ -44,7 +43,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { assertNull(myRoot.findChild("foo.txt")); } - public void testPutLabelAndRevertInstantly() throws IOException { + public void testPutLabelAndRevertInstantly() throws Exception { VirtualFile f = createChildData(myRoot, "foo.txt"); setBinaryContent(f, new byte[]{123}, -1, 4000, this); final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java index 17f7b6dcb802..3d8209264308 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java @@ -16,12 +16,15 @@ package com.intellij.openapi.diff.impl.patch.formove; import com.intellij.history.Label; +import com.intellij.history.LocalHistoryException; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.openapi.vcs.changes.ui.FilePathChangesTreeList; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.components.JBLabel; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -87,7 +90,15 @@ class UndoApplyPatchDialog extends DialogWrapper { ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { - myBeforeLabel.revert(myProject, myProject.getBaseDir()); + final VirtualFile baseDir = myProject.getBaseDir(); + try { + myBeforeLabel.revert(myProject, baseDir); + } + catch (LocalHistoryException e) { + VcsNotifier.getInstance(myProject) + .notifyImportantWarning("Rollback Failed", String.format("Try to use local history dialog for %s and perform revert manually.", + baseDir.getName())); + } } }, "Rollback Applied Changes...", true, myProject); }