[PATCH 2 of 2 V5] update: fix bare update to work on new branch (BC)

liscju piotr.listkiewicz at gmail.com
Sun Mar 13 09:58:50 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1457876685 -3600
#      Sun Mar 13 14:44:45 2016 +0100
# Node ID a8f1f4cf1450a6fff66d64540b0923ff6b10949a
# Parent  5ebf0a38f789a35d9bd1dcfd39008b365ec75477
update: fix bare update to work on new branch (BC)

So far bare update on new branch results in
'abort: branch new-branch not found'. This commit fixes
this by updating to the parent of wctx.

diff -r 5ebf0a38f789 -r a8f1f4cf1450 mercurial/destutil.py
--- a/mercurial/destutil.py	Tue Feb 23 18:51:17 2016 +0100
+++ b/mercurial/destutil.py	Sun Mar 13 14:44:45 2016 +0100
@@ -109,12 +109,11 @@ def _destupdatebranch(repo, clean, check
                 repo.ui.warn(_('uncommited branch %s does not exist, '
                                'updating to the head of parent branch\n')
                              % currentbranch)
-        else:
-            if currentbranch == 'default': # no default branch!
-                # update to the tipmost non-closed branch head
-                node = repo.revs('max(head() and not closed())').first()
-            else:
-                raise error.Abort(_("branch %s not found") % currentbranch)
+        elif repo['.']:
+            node = repo['.'].node()
+            repo.ui.warn(_('uncommited branch %s does not exist, '
+                           'updating to parent\n')
+                         % currentbranch)
     return node, movemark, None
 
 def _destupdatebranchfallback(repo, clean, check):
diff -r 5ebf0a38f789 -r a8f1f4cf1450 tests/test-newbranch.t
--- a/tests/test-newbranch.t	Tue Feb 23 18:51:17 2016 +0100
+++ b/tests/test-newbranch.t	Sun Mar 13 14:44:45 2016 +0100
@@ -211,8 +211,8 @@ Update with no arguments: tipmost revisi
   marked working directory as branch foobar
 
   $ hg up
-  abort: branch foobar not found
-  [255]
+  uncommited branch foobar does not exist, updating to parent
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Fast-forward merge:
 
@@ -396,3 +396,40 @@ and updates to the head of parent branch
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     c
   
+
+We expect that bare update on new branch, updates to parent
+
+  $ hg update -r 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch new-branch
+  marked working directory as branch new-branch
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg update
+  uncommited branch new-branch does not exist, updating to parent
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg parent
+  changeset:   1:0e067c57feba
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  $ cd ..
+
+We expect that bare update on non existing parent doesnt go anywhere
+  $ hg init newbranch-nonexisting-parent
+  $ cd newbranch-nonexisting-parent
+  $ hg branch new-branch
+  marked working directory as branch new-branch
+  (branches are permanent and global, did you want a bookmark?)
+  $ touch a
+  $ hg add a
+  $ hg status
+  A a
+  $ hg update
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg status
+  A a


More information about the Mercurial-devel mailing list