Patchwork [1,of,3] destutil: ensure we offer 'hg update' hint when not at head in all cases

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 15, 2016, 10:49 a.m.
Message ID <dfac70f47ed5ac6802eb.1455533354@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/13194/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Pierre-Yves David - Feb. 15, 2016, 10:49 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1455060921 0
#      Tue Feb 09 23:35:21 2016 +0000
# Node ID dfac70f47ed5ac6802eba6a331f36fb843c81bc7
# Parent  ade8a14a32f640eafc0e1ab3921280f508b0353b
# EXP-Topic destination
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r dfac70f47ed5
destutil: ensure we offer 'hg update' hint when not at head in all cases

In the merge case, we abort if the working copy is not at head, offering to
run 'hg update' in the hint instead. In the rebase case, we do not abort in that
case. Yet if no rebase destination are found, it still make sense to hint the
user about running 'hg update'. So we re-introduce a conditional using this
branch in the 'onheadcheck == False' case.

This will get used on rebase use this function.

Patch

diff --git a/mercurial/destutil.py b/mercurial/destutil.py
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -233,11 +233,12 @@  def _destmergebranch(repo, action='merge
                 msg, hint = msgdestmerge['multiplebranchessourceset'][action]
                 raise error.ManyMergeDestAbort(msg, hint=hint)
             branch = ctx.branch()
 
     bheads = repo.branchheads(branch)
-    if onheadcheck and not repo.revs('%ld and %ln', sourceset, bheads):
+    onhead = repo.revs('%ld and %ln', sourceset, bheads)
+    if onheadcheck and not onhead:
         # Case A: working copy if not on a head. (merge only)
         #
         # This is probably a user mistake We bailout pointing at 'hg update'
         if len(repo.heads()) <= 1:
             msg, hint = msgdestmerge['nootherheadsbehind'][action]
@@ -265,10 +266,14 @@  def _destmergebranch(repo, action='merge
         if bheads:
             msg, hint = msgdestmerge['bookmarkedheads'][action]
         elif len(repo.heads()) > 1:
             msg, hint = msgdestmerge['nootherbranchheads'][action]
             msg %= branch
+        elif not onhead:
+            # if 'onheadcheck == False' (rebase case),
+            # this was not caught in Case A.
+            msg, hint = msgdestmerge['nootherheadsbehind'][action]
         else:
             msg, hint = msgdestmerge['nootherheads'][action]
         raise error.NoMergeDestAbort(msg, hint=hint)
     else:
         node = nbhs[0]