[PATCH 3 of 5 experimental] merge: allow the update command to cross branches
Gilles Moris
gilles.moris at free.fr
Tue Sep 21 14:18:19 CDT 2010
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1284559490 -7200
# Node ID aa7865387c175398b7fa1248434ff55a9069e20c
# Parent a3f8841f8a0d1b828d2d62188c487edd6e15bdb1
merge: allow the update command to cross branches
Implicit branch crossing is still forbidden, whatever if the working directory
is dirty or not. Explicit branch crossing with a dirty WD is now allowed.
Here is the new array:
-c -C dirty rev | linear same cross
n n * n | ok (1) x
n n n y | ok ok ok
n n y y | merge merge merge
n y * * | --- discard ---
y n y * | --- (2) ---
y n n * | --- ok ---
y y * * | --- (3) ---
diff -r a3f8841f8a0d -r aa7865387c17 mercurial/commands.py
--- a/mercurial/commands.py Wed Sep 15 16:02:52 2010 +0200
+++ b/mercurial/commands.py Wed Sep 15 16:04:50 2010 +0200
@@ -3759,14 +3759,9 @@
The following rules apply when the working directory contains
uncommitted changes:
- 1. If neither -c/--check nor -C/--clean is specified, and if
- the requested changeset is an ancestor or descendant of
- the working directory's parent, the uncommitted changes
- are merged into the requested changeset and the merged
- result is left uncommitted. If the requested changeset is
- not an ancestor or descendant (that is, it is on another
- branch), the update is aborted and the uncommitted changes
- are preserved.
+ 1. If neither -c/--check nor -C/--clean is specified, the uncommitted
+ changes are merged into the requested changeset and the merged
+ result is left uncommitted.
2. With the -c/--check option, the update is aborted and the
uncommitted changes are preserved.
diff -r a3f8841f8a0d -r aa7865387c17 mercurial/merge.py
--- a/mercurial/merge.py Wed Sep 15 16:02:52 2010 +0200
+++ b/mercurial/merge.py Wed Sep 15 16:04:50 2010 +0200
@@ -467,21 +467,19 @@
This logic is tested by test-update-branches.t.
-c -C dirty rev | linear same cross
- n n n n | ok (1) x
+ n n * n | ok (1) x
n n n y | ok ok ok
- n n y * | merge (2) (2)
+ n n y y | merge merge merge
n y * * | --- discard ---
- y n y * | --- (3) ---
+ y n y * | --- (2) ---
y n n * | --- ok ---
- y y * * | --- (4) ---
+ y y * * | --- (3) ---
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' to merge or
- use 'hg update -C' to discard changes)
- 3 = abort: uncommitted local changes
- 4 = incompatible options (checked in commands.py)
+ 1 = abort: crosses branches (use 'hg update tip')
+ 2 = abort: uncommitted local changes
+ 3 = incompatible options (checked in commands.py)
"""
onode = node
@@ -521,18 +519,14 @@
raise util.Abort(_("outstanding uncommitted changes "
"(use 'hg status' to list changes)"))
elif not overwrite:
- if pa == p1: # linear forward
- pass # all good
- elif pa == p2: # linear backward
- pa = p1
- elif wc.files() or wc.deleted():
- 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')"))
+ if pa != p1 and pa != p2 and onode is None:
+ # non linear implicit update
+ raise util.Abort(_("crosses branches:"
+ " update to an explicit branch name"))
+ if wc.files() or wc.deleted():
+ pa = p1 # merge of wc in p2
else:
- # Allow jumping branches if clean and specific rev given
+ # Allow jumping to rev if clean and specific rev given
overwrite = True
### calculate phase
diff -r a3f8841f8a0d -r aa7865387c17 tests/test-merge5.t
--- a/tests/test-merge5.t Wed Sep 15 16:02:52 2010 +0200
+++ b/tests/test-merge5.t Wed Sep 15 16:04:50 2010 +0200
@@ -14,7 +14,7 @@
$ hg update 1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg update
- abort: crosses branches (use 'hg merge' or use 'hg update -c')
+ abort: crosses branches: update to an explicit branch name
[255]
$ hg update -c
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
@@ -24,14 +24,12 @@
from hanging when "hg update" erroneously prompts the user for "keep
or delete".
-Should abort:
-
- $ hg update -y 1
- abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
- [255]
- $ mv c a
-
Should succeed:
$ hg update -y 1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg status -AC
+ ! a
+ ? c
+ C b
+
diff -r a3f8841f8a0d -r aa7865387c17 tests/test-up-local-change.t
--- a/tests/test-up-local-change.t Wed Sep 15 16:02:52 2010 +0200
+++ b/tests/test-up-local-change.t Wed Sep 15 16:04:50 2010 +0200
@@ -168,7 +168,7 @@
summary: 2
$ hg --debug up || echo failed
- abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
+ abort: crosses branches: update to an explicit branch name
failed
$ hg --debug merge || echo failed
abort: outstanding uncommitted changes (use 'hg status' to list changes)
diff -r a3f8841f8a0d -r aa7865387c17 tests/test-update-branches.t
--- a/tests/test-update-branches.t Wed Sep 15 16:02:52 2010 +0200
+++ b/tests/test-update-branches.t Wed Sep 15 16:04:50 2010 +0200
@@ -77,7 +77,7 @@
parent=5
$ norevtest 'none clean same' clean 2
- abort: crosses branches (use 'hg merge' or use 'hg update -c')
+ abort: crosses branches: update to an explicit branch name
parent=2
@@ -100,13 +100,13 @@
M foo
$ revtest 'none dirty same' dirty 2 3
- abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
- parent=2
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ parent=3
M foo
$ revtest 'none dirty cross' dirty 3 4
- abort: crosses branches (use 'hg merge' to merge or use 'hg update -C' to discard changes)
- parent=3
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ parent=4
M foo
More information about the Mercurial-devel
mailing list