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

Augie Fackler raf at durin42.com
Fri Sep 20 09:46:56 CDT 2013


On Sun, Sep 08, 2013 at 08:45:09PM +1000, Stephen Lee wrote:
> # HG changeset patch
> # User Stephen Lee <sphen.lee at gmail.com>
> # Date 1378636809 -36000
> # Node ID 67f4f79481793fd635d28c9e584f024070b87277
> # Parent  4f3b94d13ecd9d35b1c7bd65e57f8700322d2816
> bookmarks: suggest 'push -B FOO' when a potentially new remote head has a local bookmark

I think I'm +1 on this series. Kevin?

>
> 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
> @@ -274,8 +274,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
> @@ -290,8 +290,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
> @@ -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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list