[PATCH] merge: when current branch has 1 or > 2 heads, actually abort

Greg Ward greg-hg at gerg.ca
Mon Jun 14 14:02:40 CDT 2010


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1276541492 14400
# Node ID a6348965cf51fe962f2395c6bc7b72646c0a40ab
# Parent  c6971a790206f824df9b25607fa4d030baad92fd
merge: when current branch has 1 or > 2 heads, actually abort.

Currently merge just prints abort-like messages to stderr and then
exits with a misleading status 0 (cleverly disguised as "False").
With this change it raises Abort, just like every other fatal error.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2561,19 +2561,20 @@
         branch = repo.changectx(None).branch()
         bheads = repo.branchheads(branch)
         if len(bheads) > 2:
-            ui.warn(_("abort: branch '%s' has %d heads - "
-                      "please merge with an explicit rev\n")
-                    % (branch, len(bheads)))
-            ui.status(_("(run 'hg heads .' to see heads)\n"))
-            return False
+            raise util.Abort(_(
+                'branch \'%s\' has %d heads -- '
+                'please merge with an explicit rev\n'
+                '(run "hg heads %s" to see all branch heads)')
+                % (branch, len(bheads), branch))
 
         parent = repo.dirstate.parents()[0]
         if len(bheads) == 1:
             if len(repo.heads()) > 1:
-                ui.warn(_("abort: branch '%s' has one head - "
-                          "please merge with an explicit rev\n" % branch))
-                ui.status(_("(run 'hg heads' to see all heads)\n"))
-                return False
+                raise util.Abort(_(
+                    'branch \'%s\' has one head -- '
+                    'please merge with an explicit rev\n'
+                    '(run "hg heads -t" to see all repository heads)')
+                    % branch)
             msg = _('there is nothing to merge')
             if parent != repo.lookup(repo[None].branch()):
                 msg = _('%s - use "hg update" instead') % msg
diff --git a/tests/test-merge-closedheads.out b/tests/test-merge-closedheads.out
--- a/tests/test-merge-closedheads.out
+++ b/tests/test-merge-closedheads.out
@@ -7,8 +7,8 @@
 created new head
 % fail with three heads
 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-abort: branch 'default' has 3 heads - please merge with an explicit rev
-(run 'hg heads .' to see heads)
+abort: branch 'default' has 3 heads -- please merge with an explicit rev
+(run "hg heads default" to see all branch heads)
 % close one of the heads
 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
 % succeed with two open heads
diff --git a/tests/test-merge-default.out b/tests/test-merge-default.out
--- a/tests/test-merge-default.out
+++ b/tests/test-merge-default.out
@@ -5,12 +5,12 @@
 created new head
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % should fail because not at a head
-abort: branch 'default' has 3 heads - please merge with an explicit rev
-(run 'hg heads .' to see heads)
+abort: branch 'default' has 3 heads -- please merge with an explicit rev
+(run "hg heads default" to see all branch heads)
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 % should fail because > 2 heads
-abort: branch 'default' has 3 heads - please merge with an explicit rev
-(run 'hg heads .' to see heads)
+abort: branch 'default' has 3 heads -- please merge with an explicit rev
+(run "hg heads default" to see all branch heads)
 % should succeed
 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
 (branch merge, don't forget to commit)
@@ -31,8 +31,8 @@
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 marked working directory as branch foobranch
 % should fail because merge with other branch
-abort: branch 'foobranch' has one head - please merge with an explicit rev
-(run 'hg heads' to see all heads)
+abort: branch 'foobranch' has one head -- please merge with an explicit rev
+(run "hg heads -t" to see all repository heads)
 % merge preview not affected by common ancestor
 2:2d95304fed5d
 4:f25cbe84d8b3
diff --git a/tests/test-newbranch.out b/tests/test-newbranch.out
--- a/tests/test-newbranch.out
+++ b/tests/test-newbranch.out
@@ -166,12 +166,12 @@
 summary:     a
 
 % implicit merge with test branch as parent
-abort: branch 'test' has one head - please merge with an explicit rev
-(run 'hg heads' to see all heads)
+abort: branch 'test' has one head -- please merge with an explicit rev
+(run "hg heads -t" to see all repository heads)
 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
-(run 'hg heads .' to see heads)
+abort: branch 'default' has 3 heads -- please merge with an explicit rev
+(run "hg heads default" to see all branch heads)
 % 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)


More information about the Mercurial-devel mailing list