diff mainwindow.cpp @ 174:4dc802a4d5ae

* Add more helpful reports when a push fails because it would create new heads
author Chris Cannam
date Thu, 16 Dec 2010 12:40:04 +0000
parents a6d336837ebe
children 6def8bf3be44
line wrap: on
line diff
--- a/mainwindow.cpp	Thu Dec 16 12:03:09 2010 +0000
+++ b/mainwindow.cpp	Thu Dec 16 12:40:04 2010 +0000
@@ -1246,6 +1246,42 @@
     QMessageBox::information(this, "Pull complete", report);
 }
 
+void MainWindow::reportNewRemoteHeads(QString output)
+{
+    bool headsAreLocal = false;
+
+    if (currentParents.size() == 1) {
+        int currentBranchHeads = 0;
+        bool parentIsHead = false;
+        Changeset *parent = currentParents[0];
+        foreach (Changeset *head, currentHeads) {
+            if (head->isOnBranch(currentBranch)) {
+                ++currentBranchHeads;
+            }
+            if (parent->id() == head->id()) {
+                parentIsHead = true;
+            }
+        }
+        if (currentBranchHeads == 2 && parentIsHead) {
+            headsAreLocal = true;
+        }
+    }
+
+    if (headsAreLocal) {
+        QMessageBox::warning
+            (this, tr("Push failed"),
+             format3(tr("Push failed"),
+                     tr("Your local repository could not be pushed to the remote repository.<br><br>You may need to merge the changes locally first.<br><br>The output of the push command was:"),
+                     output));
+    } else {
+        QMessageBox::warning
+            (this, tr("Push failed"),
+             format3(tr("Push failed"),
+                     tr("Your local repository could not be pushed to the remote repository.<br><br>The remote repository may have been changed by someone else since you last pushed. Try pulling and merging their changes into your local repository first.<br><br>The output of the push command was:"),
+                     output));
+    }
+}
+
 void MainWindow::commandFailed(HgAction action, QString output)
 {
     DEBUG << "MainWindow::commandFailed" << endl;
@@ -1274,7 +1310,11 @@
         // and some return with failure codes when something as basic
         // as the user closing the window via the wm happens
         return;
-
+    case ACT_PUSH:
+        if (output.contains("creates new remote heads")) {
+            reportNewRemoteHeads(output);
+            return;
+        }
     default:
         break;
     }