[PATCH 2 of 2 RESEND] bookmarks: suggest 'push -B FOO' when a potentially new remote head has a local bookmark

Stephen Lee sphen.lee at gmail.com
Mon Nov 11 04:53:07 CST 2013


# HG changeset patch
# User Stephen Lee <sphen.lee at gmail.com>
# Date 1384165016 -39600
#      Mon Nov 11 21:16:56 2013 +1100
# Node ID fdb1232d9c82b0d6d9c10bb47c2e7bfb7b9be7c6
# Parent  59a82b3476c080cf969711190e2afdc6f79432db
bookmarks: suggest 'push -B FOO' when a potentially new remote head has a local bookmark

If a new head is prevented from being pushed and has a local bookmark this change suggests
using 'push -B FOO' since this is somewhat safer than using force.

This does not consider if there are unsynced changes, or if the localbook exists
remotely but cannot be updated (ie. if it is divergent).  In these cases pull and/or merge
might be a better suggestion.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -327,20 +327,26 @@
             dhs = sorted(newhs - bookmarkedheads - oldhs)
         if dhs:
             if error is None:
-                if branch not in ('default', None):
+                if repo[dhs[0]].bookmarks():
+                    bm = repo[dhs[0]].bookmarks()[0]
                     error = _("push creates new remote head %s "
-                              "on branch '%s'!") % (short(dhs[0]), branch)
+                              "with bookmark '%s'") % (short(dhs[0]), bm)
+                    hint = _("use push -B %s to push this bookmark") % bm
                 else:
-                    error = _("push creates new remote head %s!"
-                              ) % short(dhs[0])
-                if heads[2]: # unsynced
-                    hint = _("pull and merge or"
-                             " see \"hg help push\" for details about"
-                             " pushing new heads")
-                else:
-                    hint = _("merge or"
-                             " see \"hg help push\" for details about"
-                             " pushing new heads")
+                    if branch not in ('default', None):
+                        error = _("push creates new remote head %s "
+                                "on branch '%s'!") % (short(dhs[0]), branch)
+                    else:
+                        error = _("push creates new remote head %s!"
+                                ) % short(dhs[0])
+                    if heads[2]: # unsynced
+                        hint = _("pull and merge or"
+                                 " see \"hg help push\" for details about"
+                                 " pushing new heads")
+                    else:
+                        hint = _("merge or"
+                                 " see \"hg help push\" for details about"
+                                 " pushing new heads")
             if branch is not None:
                 repo.ui.note(_("new remote heads on branch '%s'\n") % branch)
             for h in dhs:
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -274,8 +274,8 @@
   $ hg push http://localhost:$HGPORT2/
   pushing to http://localhost:$HGPORT2/
   searching for changes
-  abort: push creates new remote head c922c0139ca0!
-  (merge or see "hg help push" for details about pushing new heads)
+  abort: push creates new remote head c922c0139ca0 with bookmark 'Y'
+  (use push -B Y to push this bookmark)
   [255]
   $ hg -R ../a book
      @                         1:0d2164f0ce0d
@@ -290,8 +290,8 @@
   $ hg push http://localhost:$HGPORT2/
   pushing to http://localhost:$HGPORT2/
   searching for changes
-  abort: push creates new remote head c922c0139ca0!
-  (merge or see "hg help push" for details about pushing new heads)
+  abort: push creates new remote head c922c0139ca0 with bookmark 'Y'
+  (use push -B Y to push this bookmark)
   [255]
   $ hg -R ../a book
      @                         1:0d2164f0ce0d
@@ -431,6 +431,12 @@
   $ echo c5 > f2
   $ hg ci -Am5
   created new head
+  $ hg push
+  pushing to http://localhost:$HGPORT/
+  searching for changes
+  abort: push creates new remote head cc978a373a53 with bookmark 'W'
+  (use push -B W to push this bookmark)
+  [255]
   $ hg push -B W
   pushing to http://localhost:$HGPORT/
   searching for changes


More information about the Mercurial-devel mailing list