[PATCH V2] mercurial: fixes update --clean to work on new branch (issue5003)

liscju piotr.listkiewicz at gmail.com
Tue Feb 23 18:40:46 UTC 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1456249877 -3600
#      Tue Feb 23 18:51:17 2016 +0100
# Node ID 541ba7dc5f2667298c3ff2d72e5c05559a79ba92
# Parent  91a827e760df9d9b3d86692c5aa195a3d6ba2208
mercurial: fixes update --clean to work on new branch (issue5003)

So far 'hg update --clean' on newly created branch results in abort
with branch not found error. Before this patch the destination node
was resolved using instruction:

node = repo.revs('max(.::(head() and branch(%s)))'
                         , wc.branch()).first()

Problem occures when wc.branch() is newly created branch in
working directory, so there are no changeset having branch
the same as branch in working copy.

This patch fixes this problem by searching for revision having
the same branch as first parent of working directory.

diff -r 91a827e760df -r 541ba7dc5f26 mercurial/destutil.py
--- a/mercurial/destutil.py	Sun Feb 14 01:33:55 2016 +0900
+++ b/mercurial/destutil.py	Tue Feb 23 18:51:17 2016 +0100
@@ -91,13 +91,17 @@ def _destupdatebranch(repo, clean, check
     """decide on an update destination from current branch"""
     wc = repo[None]
     movemark = node = None
+    if clean:
+        branch = repo["."].branch()
+    else:
+        branch = wc.branch()
     try:
         node = repo.revs('max(.::(head() and branch(%s)))'
-                         , wc.branch()).first()
+                         , branch).first()
         if bookmarks.isactivewdirparent(repo):
             movemark = repo['.'].node()
     except error.RepoLookupError:
-        if wc.branch() == 'default': # no default branch!
+        if branch == 'default': # no default branch!
             node = repo.lookup('tip') # update to tip
         else:
             raise error.Abort(_("branch %s not found") % wc.branch())
diff -r 91a827e760df -r 541ba7dc5f26 tests/test-newbranch.t
--- a/tests/test-newbranch.t	Sun Feb 14 01:33:55 2016 +0900
+++ b/tests/test-newbranch.t	Tue Feb 23 18:51:17 2016 +0100
@@ -207,6 +207,9 @@ Update with no arguments: tipmost revisi
   $ hg id
   adf1a74a7f7b (foo) tip
 
+  $ hg branch
+  foo
+
   $ hg branch foobar
   marked working directory as branch foobar
 
@@ -214,6 +217,15 @@ Update with no arguments: tipmost revisi
   abort: branch foobar not found
   [255]
 
+  $ hg branch
+  foobar
+
+  $ hg up --clean
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg branch
+  foo
+
 Fast-forward merge:
 
   $ hg branch ff


More information about the Mercurial-devel mailing list