# HG changeset patch # User Vadim Gelfer # Date 1155667087 25200 # Node ID 013921c753bd7ad5fd653ddb4207d7c947ce0539 # Parent cd7bbb19b96e962cc30478453bf1552dbf854bc1 merge with other head by default, not tip. fixes issue 339. diff -r cd7bbb19b96e -r 013921c753bd mercurial/commands.py --- 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): diff -r cd7bbb19b96e -r 013921c753bd tests/test-merge-default --- /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 diff -r cd7bbb19b96e -r 013921c753bd tests/test-merge-default.out --- /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 diff -r cd7bbb19b96e -r 013921c753bd tests/test-up-local-change.out --- 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