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

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


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1456249877 -3600
#      Tue Feb 23 18:51:17 2016 +0100
# Node ID 5ebf0a38f789a35d9bd1dcfd39008b365ec75477
# Parent  70c2f8a982766b512e9d7f41f2d93fdb92f5481f
update: fix bare --clean to work on new branch (issue5003) (BC)

So far 'hg update --clean' on newly created branch results in abort
with branch not found error. After applying this commit bare --clean
update results in updating to the max head of the parents branch.

This seems reasonable as clean should discard uncommited changes,
branch is one of changes, and it would be unreasonable to stay on
the head of the branch we want to discard.

diff -r 70c2f8a98276 -r 5ebf0a38f789 mercurial/destutil.py
--- a/mercurial/destutil.py	Sun Mar 06 15:40:20 2016 -0800
+++ b/mercurial/destutil.py	Tue Feb 23 18:51:17 2016 +0100
@@ -102,11 +102,19 @@ def _destupdatebranch(repo, clean, check
         if bookmarks.isactivewdirparent(repo):
             movemark = repo['.'].node()
     else:
-        if currentbranch == 'default': # no default branch!
-            # update to the tipmost non-closed branch head
-            node = repo.revs('max(head() and not closed())').first()
+        if clean:
+            heads = repo.branchheads(repo['.'].branch())
+            if heads:
+                node = repo.revs('max(.::(%ln))', heads).first()
+                repo.ui.warn(_('uncommited branch %s does not exist, '
+                               'updating to the head of parent branch\n')
+                             % currentbranch)
         else:
-            raise error.Abort(_("branch %s not found") % currentbranch)
+            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)
     return node, movemark, None
 
 def _destupdatebranchfallback(repo, clean, check):
diff -r 70c2f8a98276 -r 5ebf0a38f789 tests/test-newbranch.t
--- a/tests/test-newbranch.t	Sun Mar 06 15:40:20 2016 -0800
+++ b/tests/test-newbranch.t	Tue Feb 23 18:51:17 2016 +0100
@@ -345,3 +345,54 @@ 2 branch heads, implicit merge works:
   (branch merge, don't forget to commit)
 
   $ cd ..
+
+We expects that update --clean discard changes in working directory,
+and updates to the head of parent branch.
+
+  $ hg init update_bare_clean
+  $ cd update_bare_clean
+  $ touch a
+  $ hg commit -A -m "a"
+  adding a
+  $ touch b
+  $ hg commit -A -m "b"
+  adding b
+  $ touch c
+  $ hg commit -A -m "c"
+  adding c
+  $ hg log
+  changeset:   2:991a3460af53
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  
+  changeset:   1:0e067c57feba
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  changeset:   0:3903775176ed
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a
+  
+  $ 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?)
+  $ echo "aa" >> a
+  $ hg update --clean
+  uncommited branch new-branch does not exist, updating to the head of parent branch
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg status
+  $ hg branch
+  default
+  $ hg parent
+  changeset:   2:991a3460af53
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  


More information about the Mercurial-devel mailing list