~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2006-02-11 23:18:07 UTC
  • mto: (1534.1.22 integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060211231807-30cf1893956ebb07
Create a checkout command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""builtin bzr commands"""
18
18
 
19
19
 
 
20
import errno
20
21
import os
 
22
from shutil import rmtree
21
23
import sys
22
24
 
23
25
import bzrlib
 
26
import bzrlib.branch as branch
24
27
import bzrlib.bzrdir as bzrdir
25
28
from bzrlib._merge_core import ApplyMerge3
26
29
from bzrlib.commands import Command, display_command
396
399
    takes_args = ['location?']
397
400
 
398
401
    def run(self, location=None, remember=False, overwrite=False, verbose=False):
399
 
        from shutil import rmtree
400
 
        import errno
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()
459
460
            create_prefix=False, verbose=False):
460
461
        # FIXME: Way too big!  Put this into a function called from the
461
462
        # command.
462
 
        import errno
463
 
        from shutil import rmtree
464
463
        from bzrlib.transport import get_transport
465
464
        
466
465
        tree_from = WorkingTree.open_containing(u'.')[0]
547
546
    aliases = ['get', 'clone']
548
547
 
549
548
    def run(self, from_location, to_location=None, revision=None, basis=None):
550
 
        import errno
551
 
        from shutil import rmtree
552
549
        if revision is None:
553
550
            revision = [None]
554
551
        elif len(revision) > 1:
611
608
            br_from.unlock()
612
609
 
613
610
 
 
611
class cmd_checkout(Command):
 
612
    """Create a new checkout of an existing branch.
 
613
 
 
614
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
 
615
    be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
 
616
 
 
617
    To retrieve the branch as of a particular revision, supply the --revision
 
618
    parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
 
619
    out of date [so you cannot commit] but it may be useful (i.e. to examine old
 
620
    code.)
 
621
 
 
622
    --basis is to speed up checking out from remote branches.  When specified, it
 
623
    uses the inventory and file contents from the basis branch in preference to the
 
624
    branch being checked out. [Not implemented yet.]
 
625
    """
 
626
    takes_args = ['branch_location', 'to_location?']
 
627
    # takes_options = ['revision', 'basis']
 
628
 
 
629
    def run(self, branch_location, to_location=None, revision=None, basis=None):
 
630
        if revision is None:
 
631
            revision = [None]
 
632
        elif len(revision) > 1:
 
633
            raise BzrCommandError(
 
634
                'bzr checkout --revision takes exactly 1 revision value')
 
635
        source = Branch.open(branch_location)
 
636
        if len(revision) == 1 and revision[0] is not None:
 
637
            revision_id = revision[0].in_history(source)[1]
 
638
        else:
 
639
            revision_id = None
 
640
        if to_location is None:
 
641
            to_location = os.path.basename(branch_location.rstrip("/\\"))
 
642
        try:
 
643
            os.mkdir(to_location)
 
644
        except OSError, e:
 
645
            if e.errno == errno.EEXIST:
 
646
                raise BzrCommandError('Target directory "%s" already'
 
647
                                      ' exists.' % to_location)
 
648
            if e.errno == errno.ENOENT:
 
649
                raise BzrCommandError('Parent of "%s" does not exist.' %
 
650
                                      to_location)
 
651
            else:
 
652
                raise
 
653
        checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
 
654
        branch.BranchReferenceFormat().initialize(checkout, source)
 
655
        checkout.create_workingtree()
 
656
 
 
657
 
614
658
class cmd_renames(Command):
615
659
    """Show list of renamed files.
616
660
    """