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

liscju piotr.listkiewicz at gmail.com
Wed Dec 30 19:55:38 UTC 2015


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1451505270 -3600
#      Wed Dec 30 20:54:30 2015 +0100
# Node ID a92bf43906f58c665c35bc745e6d83049a2e95c2
# Parent  23541bdd1610c08af247f9c8719045cf247ce541
mercurial: fixes update --clean to work on new branch (issue5003)

So far 'hg update --clean' on new created branch results in abort with
branch not found error. This patch fixes this by changing how destination
update branch revision is resolved when clean option is specified: it tries
to resolve branch tip, and then if it is not found it returns parent of
working directory as destination.

diff -r 23541bdd1610 -r a92bf43906f5 mercurial/destutil.py
--- a/mercurial/destutil.py	Wed Dec 23 16:22:20 2015 -0800
+++ b/mercurial/destutil.py	Wed Dec 30 20:54:30 2015 +0100
@@ -92,7 +92,12 @@
     wc = repo[None]
     movemark = node = None
     try:
-        node = repo.branchtip(wc.branch())
+        if clean:
+            node = repo.branchtip(wc.branch(), ignoremissing=True)
+            if not node:
+                node = repo['.'].node()
+        else:
+            node = repo.branchtip(wc.branch())
         if bookmarks.isactivewdirparent(repo):
             movemark = repo['.'].node()
     except error.RepoLookupError:
diff -r 23541bdd1610 -r a92bf43906f5 tests/test-newbranch.t
--- a/tests/test-newbranch.t	Wed Dec 23 16:22:20 2015 -0800
+++ b/tests/test-newbranch.t	Wed Dec 30 20:54:30 2015 +0100
@@ -214,6 +214,15 @@
   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