[PATCH 2 of 3] update: allow branch crossing without -c or -C, with no uncommitted changes

Stuart W Marks smarks at smarks.org
Sun Nov 1 22:46:36 CST 2009


# HG changeset patch
# User Stuart W Marks <smarks at smarks.org>
# Date 1257136299 28800
# Node ID 58f691f2d5aa6d0484ffb165e16ac5ca29fdbdc9
# Parent  805cd5252f7509e3dd5df39555f07ff4d58705b3
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.

diff -r 805cd5252f75 -r 58f691f2d5aa mercurial/merge.py
--- a/mercurial/merge.py	Sun Nov 01 20:31:39 2009 -0800
+++ b/mercurial/merge.py	Sun Nov 01 20:31:39 2009 -0800
@@ -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
diff -r 805cd5252f75 -r 58f691f2d5aa tests/test-merge5.out
--- a/tests/test-merge5.out	Sun Nov 01 20:31:39 2009 -0800
+++ b/tests/test-merge5.out	Sun Nov 01 20:31:39 2009 -0800
@@ -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
diff -r 805cd5252f75 -r 58f691f2d5aa tests/test-up-local-change.out
--- a/tests/test-up-local-change.out	Sun Nov 01 20:31:39 2009 -0800
+++ b/tests/test-up-local-change.out	Sun Nov 01 20:31:39 2009 -0800
@@ -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
diff -r 805cd5252f75 -r 58f691f2d5aa tests/test-update-branches.out
--- a/tests/test-update-branches.out	Sun Nov 01 20:31:39 2009 -0800
+++ b/tests/test-update-branches.out	Sun Nov 01 20:31:39 2009 -0800
@@ -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


More information about the Mercurial-devel mailing list