17
17
"""builtin bzr commands"""
22
from shutil import rmtree
27
from bzrlib.branch import Branch
24
28
import bzrlib.bzrdir as bzrdir
25
29
from bzrlib._merge_core import ApplyMerge3
26
30
from bzrlib.commands import Command, display_command
27
from bzrlib.branch import Branch
28
31
from bzrlib.revision import common_ancestor
29
32
import bzrlib.errors as errors
30
33
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
396
399
takes_args = ['location?']
398
401
def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
399
from shutil import rmtree
401
402
# FIXME: too much stuff is in the command class
402
403
tree_to = WorkingTree.open_containing(u'.')[0]
403
404
stored_loc = tree_to.branch.get_parent()
466
467
create_prefix=False, verbose=False):
467
468
# FIXME: Way too big! Put this into a function called from the
470
from shutil import rmtree
471
470
from bzrlib.transport import get_transport
473
472
tree_from = WorkingTree.open_containing(u'.')[0]
554
553
aliases = ['get', 'clone']
556
555
def run(self, from_location, to_location=None, revision=None, basis=None):
558
from shutil import rmtree
559
556
if revision is None:
560
557
revision = [None]
561
558
elif len(revision) > 1:
609
606
rmtree(to_location)
610
607
msg = "The branch %s cannot be used as a --basis"
611
608
raise BzrCommandError(msg)
612
WorkingTree.create(branch, to_location)
614
610
branch.control_files.put_utf8('branch-name', name)
617
class cmd_checkout(Command):
618
"""Create a new checkout of an existing branch.
620
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
621
be used. In other words, "checkout ../foo/bar" will attempt to create ./bar.
623
To retrieve the branch as of a particular revision, supply the --revision
624
parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
625
out of date [so you cannot commit] but it may be useful (i.e. to examine old
628
--basis is to speed up checking out from remote branches. When specified, it
629
uses the inventory and file contents from the basis branch in preference to the
630
branch being checked out. [Not implemented yet.]
632
takes_args = ['branch_location', 'to_location?']
633
takes_options = ['revision'] # , 'basis']
635
def run(self, branch_location, to_location=None, revision=None, basis=None):
638
elif len(revision) > 1:
639
raise BzrCommandError(
640
'bzr checkout --revision takes exactly 1 revision value')
641
source = Branch.open(branch_location)
642
if len(revision) == 1 and revision[0] is not None:
643
revision_id = revision[0].in_history(source)[1]
646
if to_location is None:
647
to_location = os.path.basename(branch_location.rstrip("/\\"))
649
os.mkdir(to_location)
651
if e.errno == errno.EEXIST:
652
raise BzrCommandError('Target directory "%s" already'
653
' exists.' % to_location)
654
if e.errno == errno.ENOENT:
655
raise BzrCommandError('Parent of "%s" does not exist.' %
659
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
660
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
661
checkout.create_workingtree(revision_id)
621
664
class cmd_renames(Command):
622
665
"""Show list of renamed files.
638
681
print "%s => %s" % (old_name, new_name)
684
class cmd_update(Command):
685
"""Update a tree to have the latest code committed to its branch.
687
This will perform a merge into the working tree, and may generate
688
conflicts. If you have any uncommitted changes, you will still
689
need to commit them after the update.
691
takes_args = ['dir?']
693
def run(self, dir='.'):
694
tree = WorkingTree.open_containing(dir)[0]
697
if tree.last_revision() == tree.branch.last_revision():
698
note("Tree is up to date.")
700
conflicts = tree.update()
701
note('Updated to revision %d.' %
702
(tree.branch.revision_id_to_revno(tree.last_revision()),))
641
711
class cmd_info(Command):
642
712
"""Show statistical information about a branch."""
643
713
takes_args = ['branch?']