clone: add option -u/--updaterev

This commit is contained in:
Adrian Buehlmann 2009-11-05 11:05:13 +01:00
parent d1740999b1
commit ba9637aae6
5 changed files with 408 additions and 12 deletions

View File

@ -590,22 +590,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 changeset). Otherwise, clone will initially check
out (in order of precedence): ::
a) the changeset, tag or branch specified with -u/--updaterev
b) the changeset, 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 changeset (applicable for local source repositories only).
A set of changesets (tags, or branch names) to pull may be specified
by listing each changeset (tag, or branch name) with -r/--rev.
If -r/--rev is used, the cloned repository will contain only a subset
of the changesets of the source repository. Only the set of changesets
defined by all -r/--rev options (including their direct and indirect
parent changesets) will be pulled into the destination repository.
No subsequent changesets (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
@ -625,11 +639,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
@ -3355,6 +3372,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')),

View File

@ -309,6 +309,8 @@ def clone(ui, source, dest=None, pull=False, rev=None, update=True,
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

View File

@ -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

View File

@ -54,3 +54,246 @@ checking files
% 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

View File

@ -165,7 +165,7 @@ hg: command 's' is ambiguous:
% Show all commands + options
add: include, exclude, dry-run
annotate: rev, follow, text, user, date, number, changeset, line-number, include, exclude
clone: noupdate, rev, pull, uncompressed, ssh, remotecmd
clone: noupdate, updaterev, rev, pull, uncompressed, ssh, remotecmd
commit: addremove, close-branch, include, exclude, message, logfile, date, user
diff: rev, change, text, git, nodates, show-function, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude
export: output, switch-parent, text, git, nodates