changeset 9717:68a1b9d0663e

update: allow branch crossing without -c or -C, with no uncommitted changes Update will now allow crossing branches within the same named branch, when given a specific revision, if the working dir is clean, without requiring the -c or -C option. Abort if no revision is given and this would cross branches. Minor change to abort message if uncommitted changes are found. Modify test-update-branches and output to reflect the altered case. Modify test-merge5.out to reflect the altered case. Modify test-up-local-change.out with new message.
author Stuart W Marks <smarks@smarks.org>
date Thu, 05 Nov 2009 10:53:59 +0100
parents ea8c207a0f78
children fe1b19bfe75b
files mercurial/merge.py tests/test-merge5.out tests/test-up-local-change.out tests/test-update-branches.out
diffstat 4 files changed, 24 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Thu Nov 05 10:53:36 2009 +0100
+++ b/mercurial/merge.py	Thu Nov 05 10:53:59 2009 +0100
@@ -412,24 +412,23 @@
 
     -c  -C  dirty  rev  |  linear   same  cross
      n   n    n     n   |    ok     (1)     x
-     n   n    n     y   |    ok     (1)    ok
-     n   n    y     *   |   merge   (2)    (3)
+     n   n    n     y   |    ok     ok     ok
+     n   n    y     *   |   merge   (2)    (2)
      n   y    *     *   |    ---  discard  ---
-     y   n    y     *   |    ---    (4)    ---
+     y   n    y     *   |    ---    (3)    ---
      y   n    n     *   |    ---    ok     ---
-     y   y    *     *   |    ---    (5)    ---
+     y   y    *     *   |    ---    (4)    ---
 
     x = can't happen
     * = don't-care
-    1 = abort: crosses branches (use 'hg merge' or 'hg update -C')
-    2 = abort: crosses branches (use 'hg merge' or 'hg update -C'
-                 to discard changes)
-    3 = abort: crosses named branches (use 'hg update -C' to
-                 discard changes)
-    4 = abort: uncommitted local changes
-    5 = incompatible options (checked in commands.py)
+    1 = abort: crosses branches (use 'hg merge' or 'hg update -c')
+    2 = abort: crosses branches (use 'hg merge' to merge or
+                 use 'hg update -C' to discard changes)
+    3 = abort: uncommitted local changes
+    4 = incompatible options (checked in commands.py)
     """
 
+    onode = node
     wlock = repo.wlock()
     try:
         wc = repo[None]
@@ -467,17 +466,14 @@
         elif not overwrite:
             if pa == p1 or pa == p2: # linear
                 pass # all good
-            elif p1.branch() == p2.branch():
-                if wc.files() or wc.deleted():
-                    raise util.Abort(_("crosses branches (use 'hg merge' or "
-                                       "'hg update -C' to discard changes)"))
-                raise util.Abort(_("crosses branches (use 'hg merge' "
-                                   "or 'hg update -C')"))
             elif wc.files() or wc.deleted():
-                raise util.Abort(_("crosses named branches (use "
-                                   "'hg update -C' to discard changes)"))
+                raise util.Abort(_("crosses branches (use 'hg merge' to merge "
+                                 "or use 'hg update -C' to discard changes)"))
+            elif onode is None:
+                raise util.Abort(_("crosses branches (use 'hg merge' or use "
+                                   "'hg update -c')"))
             else:
-                # Allow jumping branches if there are no changes
+                # Allow jumping branches if clean and specific rev given
                 overwrite = True
 
         ### calculate phase
--- a/tests/test-merge5.out	Thu Nov 05 10:53:36 2009 +0100
+++ b/tests/test-merge5.out	Thu Nov 05 10:53:59 2009 +0100
@@ -2,6 +2,6 @@
 removing b
 created new head
 % should abort
-abort: crosses branches (use 'hg merge' or 'hg update -C' to discard changes)
+abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
 % should succeed
-abort: crosses branches (use 'hg merge' or 'hg update -C')
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
--- a/tests/test-up-local-change.out	Thu Nov 05 10:53:36 2009 +0100
+++ b/tests/test-up-local-change.out	Thu Nov 05 10:53:59 2009 +0100
@@ -111,7 +111,7 @@
 date:        Mon Jan 12 13:46:40 1970 +0000
 summary:     2
 
-abort: crosses branches (use 'hg merge' or 'hg update -C' to discard changes)
+abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
 failed
 abort: outstanding uncommitted changes (use 'hg status' to list changes)
 failed
--- a/tests/test-update-branches.out	Thu Nov 05 10:53:36 2009 +0100
+++ b/tests/test-update-branches.out	Thu Nov 05 10:53:59 2009 +0100
@@ -16,14 +16,14 @@
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 parent=5
 % norevtest none clean same 2
-abort: crosses branches (use 'hg merge' or 'hg update -C')
+abort: crosses branches (use 'hg merge' or use 'hg update -c')
 parent=2
 % revtest none clean linear 1 2
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 parent=2
 % revtest none clean same 2 3
-abort: crosses branches (use 'hg merge' or 'hg update -C')
-parent=2
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+parent=3
 % revtest none clean cross 3 4
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 parent=4
@@ -32,11 +32,11 @@
 parent=2
 M foo
 % revtest none dirty same 2 3
-abort: crosses branches (use 'hg merge' or 'hg update -C' to discard changes)
+abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
 parent=2
 M foo
 % revtest none dirty cross 3 4
-abort: crosses named branches (use 'hg update -C' to discard changes)
+abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
 parent=3
 M foo
 % revtest -C dirty linear 1 2