[PATCH] clone: fix updaterev to update to latest branch changeset (issue4528)

liscju piotr.listkiewicz at gmail.com
Sun Aug 30 09:51:43 UTC 2015


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1440928063 -7200
#      Sun Aug 30 11:47:43 2015 +0200
# Branch stable
# Node ID ecbba4a3e976e739a7e20fec6722e9e6cb4a79dd
# Parent  b930d4ef7739440161c3ab7e3c831bfdb541c81e
clone: fix updaterev to update to latest branch changeset (issue4528)

Before this patch if clone --updaterev points to branch which head
on src repo wasnt in dest repo, clone updated dest repo to
default branch. After applying this patch, if changeset from
src repo pointing at given branch is not in dest repo, it searches
for changeset pointing for given branch locally in dest repo.

Lookup in destination repo:
  559: uprev = destrepo.lookup(update)
is wrapped by try/except block to preserve current behaviour when
given revset to -u is not found - it will not fail,but silently update
dest repo to head of default branch.

diff -r b930d4ef7739 -r ecbba4a3e976 mercurial/hg.py
--- a/mercurial/hg.py	Tue Aug 18 18:37:50 2015 -0500
+++ b/mercurial/hg.py	Sun Aug 30 11:47:43 2015 +0200
@@ -558,7 +558,10 @@
                     try:
                         uprev = destrepo.lookup(checkout)
                     except error.RepoLookupError:
-                        pass
+                        try:
+                            uprev = destrepo.lookup(update)
+                        except error.RepoLookupError:
+                            pass
                 if uprev is None:
                     try:
                         uprev = destrepo._bookmarks['@']
diff -r b930d4ef7739 -r ecbba4a3e976 tests/test-clone-r.t
--- a/tests/test-clone-r.t	Tue Aug 18 18:37:50 2015 -0500
+++ b/tests/test-clone-r.t	Sun Aug 30 11:47:43 2015 +0200
@@ -218,3 +218,26 @@
   4 files, 9 changesets, 7 total revisions
   $ cd ..
 
+  $ hg clone test test-9
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd test-9
+  $ hg branch foobar
+  marked working directory as branch foobar
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo file2 >> file2
+  $ hg add file2
+  $ hg commit -m "changeset9"
+  $ echo file3 >> file3
+  $ hg add file3
+  $ hg commit -m "changeset10"
+  $ cd ..
+  $ hg clone -r 9 -u foobar test-9 test-10
+  adding changesets
+  adding manifests
+  adding file changes
+  added 6 changesets with 6 changes to 3 files
+  updating to branch foobar
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+


More information about the Mercurial-devel mailing list