[PATCH] clone: add option -u/--updaterev
Adrian Buehlmann
adrian at cadifra.com
Thu Oct 22 17:27:34 UTC 2009
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1256229650 -7200
# Node ID 3aeaa46f589890655738a463e842009ea851bf6f
# Parent 1c34fca5d785ac725e7b482cfb48b65d2793e838
clone: add option -u/--updaterev
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -591,22 +591,36 @@ def clone(ui, source, dest=None, **opts)
The location of the source is added to the new repository's
.hg/hgrc file, as the default to be used for future pulls.
- If you use the -r/--rev option to clone up to a specific revision,
- no subsequent revisions (including subsequent tags) will be
- present in the cloned repository. This option implies --pull, even
- on local repositories.
-
- By default, clone will check out the head of the 'default' branch.
- If the -U/--noupdate option is used, the new clone will contain
- only a repository (.hg) and no working copy (the working copy
- parent is the null revision).
-
See 'hg help urls' for valid source format details.
It is possible to specify an ssh:// URL as the destination, but no
.hg/hgrc and working directory will be created on the remote side.
Please see 'hg help urls' for important details about ssh:// URLs.
+ If the -U/--noupdate option is specified, the new clone will contain
+ only a repository (.hg) and no working copy (the working copy parent
+ will be the null revision). Otherwise, clone will initially check
+ out (in order of precedence): ::
+
+ a) the revision, tag or branch specified with -u/--updaterev
+ b) the revision, tag or branch given with the first -r/--rev
+ c) the head of the default branch
+
+ Use 'hg clone -u . src dst' to checkout the source repository's
+ parent revision (applicable for local source repositories only).
+
+ A set of revisions (tags, or branch names) to pull may be specified
+ by listing each revision (tag, or branch name) with -r/--rev.
+ If -r/--rev is used, the cloned repository will contain only a subset
+ of the revisions of the source repository. Only the set of revisions
+ defined by all -r/--rev options (including their direct and indirect
+ parent revisions) will be pulled into the destination repository.
+ No subsequent revisions (including subsequent tags) will be present
+ in the destination.
+
+ Using -r/--rev (or 'clone src#rev dest') implies --pull, even for
+ local source repositories.
+
For efficiency, hardlinks are used for cloning whenever the source
and destination are on the same filesystem (note this applies only
to the repository data, not to the checked out files). Some
@@ -626,11 +640,14 @@ def clone(ui, source, dest=None, **opts)
this is not compatible with certain extensions that place their
metadata under the .hg directory, such as mq.
"""
+ if opts.get('noupdate') and opts.get('updaterev'):
+ raise util.Abort(_("cannot specify both --noupdate and --updaterev"))
+
hg.clone(cmdutil.remoteui(ui, opts), source, dest,
pull=opts.get('pull'),
stream=opts.get('uncompressed'),
rev=opts.get('rev'),
- update=not opts.get('noupdate'))
+ update=opts.get('updaterev') or not opts.get('noupdate'))
def commit(ui, repo, *pats, **opts):
"""commit the specified files or all outstanding changes
@@ -3347,6 +3364,8 @@ table = {
(clone,
[('U', 'noupdate', None,
_('the clone will only contain a repository (no working copy)')),
+ ('u', 'updaterev', '',
+ _('revision, tag or branch to check out')),
('r', 'rev', [],
_('a changeset you would like to have after cloning')),
('', 'pull', None, _('use pull protocol to copy metadata')),
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -309,6 +309,8 @@ def clone(ui, source, dest=None, pull=Fa
if update:
if update is not True:
checkout = update
+ if src_repo.local():
+ checkout = src_repo.lookup(update)
for test in (checkout, 'default', 'tip'):
if test is None:
continue
diff --git a/tests/test-clone b/tests/test-clone
--- a/tests/test-clone
+++ b/tests/test-clone
@@ -67,4 +67,136 @@ cd h
hg clone ../a .
cd ..
+echo
+echo
+echo % "*** tests for option -u ***"
+echo
+
+
+echo
+echo % "adding some more history to repo a"
+cd a
+echo % "tag ref1"
+hg tag ref1
+echo the quick brown fox >a
+hg ci -m "hacked default"
+echo % "updating back to ref1"
+hg up ref1
+echo
+echo % "add branch 'stable' to repo a for later tests"
+hg branch stable
+echo some text >a
+hg ci -m "starting branch stable"
+echo % "tag ref2"
+hg tag ref2
+echo some more text >a
+hg ci -m "another change for branch stable"
+echo
+echo % "updating back to ref2"
+hg up ref2
+echo
+echo % "parents of repo a"
+hg parents
+echo
+echo % "repo a has two heads"
+hg heads
+cd ..
+
+echo
+echo % "testing clone -U -u 1 a ua (must abort)"
+hg clone -U -u 1 a ua
+
+echo
+echo % "testing clone -u . a ua"
+hg clone -u . a ua
+echo
+echo % "repo ua has both heads"
+hg -R ua heads
+echo
+echo % "same revision checked out in repo a and ua"
+hg -R a parents --template "{node|short}\n"
+hg -R ua parents --template "{node|short}\n"
+rm -r ua
+
+echo
+echo % "testing clone --pull -u . a ua"
+hg clone --pull -u . a ua
+echo
+echo % "repo ua has both heads"
+hg -R ua heads
+echo
+echo % "same revision checked out in repo a and ua"
+hg -R a parents --template "{node|short}\n"
+hg -R ua parents --template "{node|short}\n"
+rm -r ua
+
+echo
+echo % "testing clone -u stable a ua"
+hg clone -u stable a ua
+echo
+echo % "repo ua has both heads"
+hg -R ua heads
+echo
+echo % "branch stable is checked out"
+hg -R ua parents
+rm -r ua
+
+echo
+echo % "testing clone a ua"
+hg clone a ua
+echo
+echo % "repo ua has both heads"
+hg -R ua heads
+echo
+echo % "branch default is checked out"
+hg -R ua parents
+rm -r ua
+
+echo
+echo % "testing clone -u . a#stable ua"
+hg clone -u . a#stable ua
+echo
+echo % "repo ua has only branch stable"
+hg -R ua heads
+echo
+echo % "same revision checked out in repo a and ua"
+hg -R a parents --template "{node|short}\n"
+hg -R ua parents --template "{node|short}\n"
+rm -r ua
+
+echo
+echo % "testing clone -u . -r stable a ua"
+hg clone -u . -r stable a ua
+echo
+echo % "repo ua has only branch stable"
+hg -R ua heads
+echo
+echo % "same revision checked out in repo a and ua"
+hg -R a parents --template "{node|short}\n"
+hg -R ua parents --template "{node|short}\n"
+rm -r ua
+
+echo
+echo % "testing clone -r stable a ua"
+hg clone -r stable a ua
+echo
+echo % "repo ua has only branch stable"
+hg -R ua heads
+echo
+echo % "branch stable is checked out"
+hg -R ua parents
+rm -r ua
+
+echo
+echo % "testing clone -u . -r stable -r default a ua"
+hg clone -u . -r stable -r default a ua
+echo
+echo % "repo ua has two heads"
+hg -R ua heads
+echo
+echo % "same revision checked out in repo a and ua"
+hg -R a parents --template "{node|short}\n"
+hg -R ua parents --template "{node|short}\n"
+rm -r ua
+
exit 0
diff --git a/tests/test-clone.out b/tests/test-clone.out
--- a/tests/test-clone.out
+++ b/tests/test-clone.out
@@ -54,3 +54,246 @@ 2 files, 11 changesets, 11 total revisio
% clone to .
updating to branch default
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+
+% *** tests for option -u ***
+
+
+% adding some more history to repo a
+% tag ref1
+% updating back to ref1
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+% add branch 'stable' to repo a for later tests
+marked working directory as branch stable
+created new head
+% tag ref2
+
+% updating back to ref2
+1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+% parents of repo a
+changeset: 13:e8ece76546a6
+branch: stable
+tag: ref2
+parent: 10:a7949464abda
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: starting branch stable
+
+
+% repo a has two heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% testing clone -U -u 1 a ua (must abort)
+abort: cannot specify both --noupdate and --updaterev
+
+% testing clone -u . a ua
+updating to branch stable
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has both heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% same revision checked out in repo a and ua
+e8ece76546a6
+e8ece76546a6
+
+% testing clone --pull -u . a ua
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 16 changesets with 16 changes to 3 files (+1 heads)
+updating to branch stable
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has both heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% same revision checked out in repo a and ua
+e8ece76546a6
+e8ece76546a6
+
+% testing clone -u stable a ua
+updating to branch stable
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has both heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% branch stable is checked out
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+
+% testing clone a ua
+updating to branch default
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has both heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% branch default is checked out
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% testing clone -u . a#stable ua
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 14 changesets with 14 changes to 3 files
+updating to branch stable
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has only branch stable
+changeset: 13:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+
+% same revision checked out in repo a and ua
+e8ece76546a6
+e8ece76546a6
+
+% testing clone -u . -r stable a ua
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 14 changesets with 14 changes to 3 files
+updating to branch stable
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has only branch stable
+changeset: 13:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+
+% same revision checked out in repo a and ua
+e8ece76546a6
+e8ece76546a6
+
+% testing clone -r stable a ua
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 14 changesets with 14 changes to 3 files
+updating to branch stable
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has only branch stable
+changeset: 13:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+
+% branch stable is checked out
+changeset: 13:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+
+% testing clone -u . -r stable -r default a ua
+requesting all changes
+adding changesets
+adding manifests
+adding file changes
+added 16 changesets with 16 changes to 3 files (+1 heads)
+updating to branch stable
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+% repo ua has two heads
+changeset: 15:0aae7cf88f0d
+branch: stable
+tag: tip
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: another change for branch stable
+
+changeset: 12:f21241060d6a
+user: test
+date: Thu Jan 01 00:00:00 1970 +0000
+summary: hacked default
+
+
+% same revision checked out in repo a and ua
+e8ece76546a6
+e8ece76546a6
More information about the Mercurial-devel
mailing list