changeset 2915:013921c753bd

merge with other head by default, not tip. fixes issue 339.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Tue, 15 Aug 2006 11:38:07 -0700
parents cd7bbb19b96e
children 68cea0b8f992
files mercurial/commands.py tests/test-merge-default tests/test-merge-default.out tests/test-up-local-change.out
diffstat 4 files changed, 79 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Aug 15 09:37:58 2006 -0700
+++ b/mercurial/commands.py	Tue Aug 15 11:38:07 2006 -0700
@@ -1969,9 +1969,29 @@
     requested revision. Files that changed between either parent are
     marked as changed for the next commit and a commit must be
     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,
+    the other head is merged with by default.  Otherwise, an explicit
+    revision to merge with must be provided.
     """
 
-    node = _lookup(repo, node, branch)
+    if node:
+        node = _lookup(repo, node, branch)
+    else:
+        heads = repo.heads()
+        if len(heads) > 2:
+            raise util.Abort(_('repo has %d heads - '
+                               'please merge with an explicit rev') %
+                             len(heads))
+        if len(heads) == 1:
+            raise util.Abort(_('there is nothing to merge - '
+                               'use "hg update" instead'))
+        parent = repo.dirstate.parents()[0]
+        if parent not in heads:
+            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]
     return hg.merge(repo, node, force=force)
 
 def outgoing(ui, repo, dest=None, **opts):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-merge-default	Tue Aug 15 11:38:07 2006 -0700
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+hg init
+echo a > a
+hg commit -A -ma
+
+echo a >> a
+hg commit -mb
+
+echo a >> a
+hg commit -mc
+
+hg up 1
+echo a >> a
+hg commit -md
+
+hg up 1
+echo a >> a
+hg commit -me
+
+hg up 1
+echo % should fail because not at a head
+hg merge
+
+hg up
+echo % should fail because \> 2 heads
+hg merge
+
+echo % should succeed
+hg merge 2
+hg commit -mm1
+
+echo % should succeed - 2 heads
+hg merge
+hg commit -mm2
+
+echo % should fail because 1 head
+hg merge
+
+true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-merge-default.out	Tue Aug 15 11:38:07 2006 -0700
@@ -0,0 +1,17 @@
+adding a
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+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
+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
+% should succeed
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+% should succeed - 2 heads
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+(branch merge, don't forget to commit)
+% should fail because 1 head
+abort: there is nothing to merge - use "hg update" instead
--- a/tests/test-up-local-change.out	Tue Aug 15 09:37:58 2006 -0700
+++ b/tests/test-up-local-change.out	Tue Aug 15 11:38:07 2006 -0700
@@ -43,7 +43,7 @@
 date:        Mon Jan 12 13:46:40 1970 +0000
 summary:     1
 
-abort: there is nothing to merge, just use 'hg update' or look at 'hg heads'
+abort: there is nothing to merge - use "hg update" instead
 failed
 changeset:   0:33aaa84a386b
 user:        test