changeset 6723:1fe6f365df2e

merge: only in-branch merges can be implicit
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 23 Jun 2008 15:02:52 +0200
parents 197d54d82f8d
children d43707e09b02
files mercurial/commands.py tests/test-command-template tests/test-convert-clonebranches tests/test-merge-default.out tests/test-newbranch tests/test-newbranch.out
diffstat 6 files changed, 109 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Jun 23 15:03:22 2008 +0200
+++ b/mercurial/commands.py	Mon Jun 23 15:02:52 2008 +0200
@@ -1891,7 +1891,7 @@
     performed before any further updates are allowed.
 
     If no revision is specified, the working directory's parent is a
-    head revision, and the repository contains exactly one other head,
+    head revision, and the current branch contains exactly one other head,
     the other head is merged with by default. Otherwise, an explicit
     revision to merge with must be provided.
     """
@@ -1902,22 +1902,28 @@
         node = rev
 
     if not node:
-        heads = repo.heads()
-        if len(heads) > 2:
-            raise util.Abort(_('repo has %d heads - '
-                               'please merge with an explicit rev') %
-                             len(heads))
+        branch = repo.workingctx().branch()
+        bheads = repo.branchheads()
+        if len(bheads) > 2:
+            raise util.Abort(_("branch '%s' has %d heads - "
+                               "please merge with an explicit rev") %
+                             (branch, len(bheads)))
+
         parent = repo.dirstate.parents()[0]
-        if len(heads) == 1:
+        if len(bheads) == 1:
+            if len(repo.heads()) > 1:
+                raise util.Abort(_("branch '%s' has one head - "
+                                   "please merge with an explicit rev") %
+                                 branch)
             msg = _('there is nothing to merge')
             if parent != repo.lookup(repo.workingctx().branch()):
                 msg = _('%s - use "hg update" instead') % msg
             raise util.Abort(msg)
 
-        if parent not in heads:
+        if parent not in bheads:
             raise util.Abort(_('working dir not at a head rev - '
                                'use "hg update" or merge with an explicit rev'))
-        node = parent == heads[0] and heads[-1] or heads[0]
+        node = parent == bheads[0] and bheads[-1] or bheads[0]
     return hg.merge(repo, node, force=force)
 
 def outgoing(ui, repo, dest=None, **opts):
--- a/tests/test-command-template	Mon Jun 23 15:03:22 2008 +0200
+++ b/tests/test-command-template	Mon Jun 23 15:02:52 2008 +0200
@@ -23,7 +23,7 @@
 echo other 4 >> d
 hg add d
 hg commit -m 'new head' -d '1500000 0' -u 'person'
-hg merge -q
+hg merge -q foo
 hg commit -m 'merge' -d '1500001 0' -u 'person'
 # second branch starting at nullrev
 hg update null
--- a/tests/test-convert-clonebranches	Mon Jun 23 15:03:22 2008 +0200
+++ b/tests/test-convert-clonebranches	Mon Jun 23 15:02:52 2008 +0200
@@ -17,7 +17,7 @@
 echo b > b
 hg ci -qAm addb
 hg up -qC
-hg merge
+hg merge default
 hg ci -qm mergeab
 hg tag -ql mergeab
 cd ..
--- a/tests/test-merge-default.out	Mon Jun 23 15:03:22 2008 +0200
+++ b/tests/test-merge-default.out	Mon Jun 23 15:02:52 2008 +0200
@@ -5,10 +5,10 @@
 created new head
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % should fail because not at a head
-abort: repo has 3 heads - please merge with an explicit rev
+abort: branch 'default' has 3 heads - please merge with an explicit rev
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % should fail because > 2 heads
-abort: repo has 3 heads - please merge with an explicit rev
+abort: branch 'default' has 3 heads - please merge with an explicit rev
 % should succeed
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
--- a/tests/test-newbranch	Mon Jun 23 15:03:22 2008 +0200
+++ b/tests/test-newbranch	Mon Jun 23 15:02:52 2008 +0200
@@ -24,7 +24,7 @@
 echo bleah > a
 hg ci -m "modify a branch" -d "1000000 0"
 
-hg merge
+hg merge default
 hg branch
 hg ci -m "merge" -d "1000000 0"
 hg log
@@ -73,4 +73,38 @@
 hg parents
 hg manifest
 
-exit 0
+echo % test merging, add 3 default heads and one test head
+cd ..
+hg init merges
+cd merges
+echo a > a
+hg ci -Ama
+
+echo b > b
+hg ci -Amb
+
+hg up 0
+echo c > c
+hg ci -Amc
+
+hg up 0
+echo d > d
+hg ci -Amd
+
+hg up 0
+hg branch test
+echo e >> e
+hg ci -Ame
+
+hg log
+
+echo % implicit merge with test branch as parent
+hg merge
+hg up -C default
+echo % implicit merge with default branch as parent
+hg merge
+echo % 3 branch heads, explicit merge required
+hg merge 2
+hg ci -m merge
+echo % 2 branch heads, implicit merge works
+hg merge
--- a/tests/test-newbranch.out	Mon Jun 23 15:03:22 2008 +0200
+++ b/tests/test-newbranch.out	Mon Jun 23 15:02:52 2008 +0200
@@ -116,3 +116,57 @@
 
 a
 ff
+% test merging, add 3 default heads and one test head
+adding a
+adding b
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding c
+created new head
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+adding d
+created new head
+0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+marked working directory as branch test
+adding e
+created new head
+changeset:   4:3a1e01ed1df4
+branch:      test
+tag:         tip
+parent:      0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     e
+
+changeset:   3:980f7dc84c29
+parent:      0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     d
+
+changeset:   2:d36c0562f908
+parent:      0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+changeset:   1:d2ae7f538514
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+changeset:   0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+% implicit merge with test branch as parent
+abort: branch 'test' has one head - please merge with an explicit rev
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+% implicit merge with default branch as parent
+abort: branch 'default' has 3 heads - please merge with an explicit rev
+% 3 branch heads, explicit merge required
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+% 2 branch heads, implicit merge works
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)