From patchwork Wed Mar 13 11:13:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 2, RFC] bookmarks: suggest 'push -B FOO' when a potentially new remote head has a local bookmark From: Stephen Lee X-Patchwork-Id: 1122 Message-Id: To: mercurial-devel@selenic.com Date: Wed, 13 Mar 2013 22:13:33 +1100 # HG changeset patch # User Stephen Lee # Date 1363172356 -39600 # Node ID e427733ad9227aea8b6756e37aa023847d4ca3f2 # Parent 8dc95dea42930a4fa251f3bd67a3eb759b51e304 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 @@ -319,18 +319,24 @@ 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 = _("you should pull and merge or " - "use push -f to force") - else: - hint = _("did you forget to merge? " - "use push -f to force") + 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 = _("you should pull and merge or " + "use push -f to force") + else: + hint = _("did you forget to merge? " + "use push -f to force") 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 @@ -241,8 +241,8 @@ $ hg push http://localhost:$HGPORT2/ pushing to http://localhost:$HGPORT2/ searching for changes - abort: push creates new remote head c922c0139ca0! - (did you forget to merge? use push -f to force) + 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 @@ -257,8 +257,8 @@ $ hg push http://localhost:$HGPORT2/ pushing to http://localhost:$HGPORT2/ searching for changes - abort: push creates new remote head c922c0139ca0! - (did you forget to merge? use push -f to force) + 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 @@ -399,6 +399,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