Git update: don't unstash/unshelve if rebase/merge process wasn't finished (returning... cidr/106.380
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Tue, 5 Apr 2011 12:09:21 +0000 (16:09 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Tue, 5 Apr 2011 12:11:59 +0000 (16:11 +0400)
plugins/git4idea/src/git4idea/update/GitChangesSaver.java
plugins/git4idea/src/git4idea/update/GitUpdateProcess.java

index 6c65d9d7f71427c143769ea3d5e1fd0198acbdde..cd275d55b89ac655c0d094fdfa9bc4283e6b8869 100644 (file)
@@ -17,6 +17,8 @@ package git4idea.update;
 
 import com.intellij.notification.Notification;
 import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
+import com.intellij.notification.Notifications;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
@@ -27,8 +29,8 @@ import com.intellij.openapi.vcs.changes.ChangeListManagerEx;
 import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.util.Consumer;
 import com.intellij.util.continuation.ContinuationContext;
+import git4idea.GitVcs;
 import git4idea.config.GitVcsSettings;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -105,6 +107,17 @@ public abstract class GitChangesSaver {
     load(getRestoreListsRunnable(), context);
   }
 
+  public void notifyLocalChangesAreNotRestored() {
+    if (wereChangesSaved()) {
+      LOG.info("Update is incomplete, changes are not restored");
+      Notifications.Bus.notify(new Notification(GitVcs.IMPORTANT_ERROR_NOTIFICATION, "Local changes were not restored",
+                                                "Before update your uncommitted changes were saved to <a href='saver'>" + getSaverName() + "</a><br/>" +
+                                                "Update is not complete, you have unresolved merges in your working tree<br/>" +
+                                                "Resolve conflicts, complete update and restore changes manually.", NotificationType.WARNING,
+                                                new ShowSavedChangesNotificationListener()));
+    }
+  }
+
   public List<LocalChangeList> getChangeLists() {
     return myChangeLists == null ? myChangeManager.getChangeLists() : myChangeLists;
   }
index 6ec253104ab63d0a825647aa5aa2e5b757bed060..9393eb01cae8045515706c04125e0a9428622af0 100644 (file)
@@ -144,6 +144,7 @@ public class GitUpdateProcess {
       mySaver.saveLocalChanges(rootsToSave);
 
       // update each root
+      boolean incomplete = false;
       boolean success = true;
       VirtualFile currentlyUpdatedRoot = null;
       try {
@@ -152,6 +153,9 @@ public class GitUpdateProcess {
           GitUpdater updater = entry.getValue();
           GitUpdateResult res = updater.update();
           LOG.info("updating root " + currentlyUpdatedRoot + " finished: " + res);
+          if (res == GitUpdateResult.INCOMPLETE) {
+            incomplete = true;
+          }
           success &= res.isSuccess();
         }
       } catch (VcsException e) {
@@ -160,7 +164,11 @@ public class GitUpdateProcess {
         notifyImportantError(myProject, "Error updating " + rootName,
                              "Updating " + rootName + " failed with an error: " + e.getLocalizedMessage());
       } finally {
-        restoreLocalChanges(context);
+        if (!incomplete) {
+          restoreLocalChanges(context);
+        } else {
+          mySaver.notifyLocalChangesAreNotRestored();
+        }
       }
       return success;
     } catch (VcsException e) {
@@ -176,7 +184,7 @@ public class GitUpdateProcess {
     context.addExceptionHandler(VcsException.class, new Consumer<VcsException>() {
       @Override
       public void consume(VcsException e) {
-        LOG.info("Couldn't restore local changes after reordering commits", e);
+        LOG.info("Couldn't restore local changes after update", e);
         notifyImportantError(myProject, "Couldn't restore local changes after update",
                              "Restoring changes saved before update failed with an error.<br/>" + e.getLocalizedMessage());
       }