changeset 7045:f82938c87b92

clone: honor -r even when pulling named branches
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Wed, 24 Sep 2008 13:10:09 +0200
parents e51c0f41f271
children fe71e5a12a50 6788608627c4
files mercurial/hg.py tests/test-issue1306 tests/test-issue1306.out tests/test-url-rev.out
diffstat 4 files changed, 101 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Sat Sep 20 15:00:58 2008 +0200
+++ b/mercurial/hg.py	Wed Sep 24 13:10:09 2008 +0200
@@ -20,10 +20,11 @@
     '''parse url#branch, returning url, branch + revs'''
 
     if '#' not in url:
-        return url, (revs or None), None
+        return url, (revs or None), revs and revs[-1] or None
 
-    url, rev = url.split('#', 1)
-    return url, revs + [rev], rev
+    url, branch = url.split('#', 1)
+    checkout = revs and revs[-1] or branch
+    return url, revs + [branch], checkout
 
 schemes = {
     'bundle': bundlerepo,
@@ -110,7 +111,7 @@
     else:
         src_repo = source
         origsource = source = src_repo.url()
-        checkout = None
+        checkout = rev and rev[-1] or None
 
     if dest is None:
         dest = defaultdest(source)
@@ -245,12 +246,13 @@
 
             if update:
                 dest_repo.ui.status(_("updating working directory\n"))
-                if not checkout:
+                for test in (checkout, 'default', 'tip'):
                     try:
-                        checkout = dest_repo.lookup("default")
+                        uprev = dest_repo.lookup(test)
+                        break
                     except:
-                        checkout = dest_repo.changelog.tip()
-                _update(dest_repo, checkout)
+                        continue
+                _update(dest_repo, uprev)
 
         return src_repo, dest_repo
     finally:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-issue1306	Wed Sep 24 13:10:09 2008 +0200
@@ -0,0 +1,23 @@
+echo % initialize remote repo with branches
+hg init remote
+cd remote
+echo a > a
+hg ci -Ama
+hg branch br
+hg ci -Amb
+echo c > c
+hg ci -Amc
+hg log
+
+cd ..
+echo % try cloning -r branch
+hg clone -rbr remote local1
+hg -R local1 parents
+
+echo % try cloning -rother clone#branch
+hg clone -r0 remote#br local2
+hg -R local2 parents
+
+echo % try cloning -r1 clone#branch
+hg clone -r1 remote#br local3
+hg -R local3 parents
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-issue1306.out	Wed Sep 24 13:10:09 2008 +0200
@@ -0,0 +1,64 @@
+% initialize remote repo with branches
+adding a
+marked working directory as branch br
+adding c
+changeset:   2:1630aed6ed2b
+branch:      br
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+changeset:   1:234f53e6c5ff
+branch:      br
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
+changeset:   0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+% try cloning -r branch
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 2 changes to 2 files
+updating working directory
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+changeset:   2:1630aed6ed2b
+branch:      br
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     c
+
+% try cloning -rother clone#branch
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 2 changes to 2 files
+updating working directory
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+changeset:   0:cb9a9f314b8b
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     a
+
+% try cloning -r1 clone#branch
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 2 changes to 2 files
+updating working directory
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+changeset:   1:234f53e6c5ff
+branch:      br
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+summary:     b
+
--- a/tests/test-url-rev.out	Sat Sep 20 15:00:58 2008 +0200
+++ b/tests/test-url-rev.out	Wed Sep 24 13:10:09 2008 +0200
@@ -109,11 +109,12 @@
 1:cd2a86ecc814
 % pull -u -r otherrev url#rev updates to rev
 % parents
-changeset:   2:faba9097cad4
-branch:      foo
+changeset:   3:4cd725637392
+tag:         tip
+parent:      0:1f0dee641bb7
 user:        test
 date:        Thu Jan 01 00:00:00 1970 +0000
-summary:     new head of branch foo
+summary:     add bar
 
 % heads
 changeset:   3:4cd725637392