~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge bzr.dev and tree implementation tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sys
25
25
 
26
26
import bzrlib
 
27
from bzrlib import (
 
28
    branch,
 
29
    bundle,
 
30
    bzrdir,
 
31
    config,
 
32
    errors,
 
33
    ignores,
 
34
    log,
 
35
    osutils,
 
36
    repository,
 
37
    transport,
 
38
    ui,
 
39
    urlutils,
 
40
    )
27
41
from bzrlib.branch import Branch, BranchReferenceFormat
28
 
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
29
 
    repository, log)
30
42
from bzrlib.bundle import read_bundle_from_url
31
43
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
44
from bzrlib.conflicts import ConflictList
42
54
from bzrlib.revisionspec import RevisionSpec
43
55
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
44
56
from bzrlib.transport.local import LocalTransport
45
 
import bzrlib.urlutils as urlutils
46
57
from bzrlib.workingtree import WorkingTree
47
58
 
48
59
 
516
527
            create_prefix=False, verbose=False):
517
528
        # FIXME: Way too big!  Put this into a function called from the
518
529
        # command.
519
 
        from bzrlib.transport import get_transport
520
530
        
521
531
        br_from = Branch.open_containing('.')[0]
522
532
        stored_loc = br_from.get_push_location()
529
539
                self.outf.write("Using saved location: %s\n" % display_url)
530
540
                location = stored_loc
531
541
 
532
 
        transport = get_transport(location)
533
 
        location_url = transport.base
 
542
        to_transport = transport.get_transport(location)
 
543
        location_url = to_transport.base
534
544
 
535
545
        old_rh = []
536
546
        try:
538
548
            br_to = dir_to.open_branch()
539
549
        except NotBranchError:
540
550
            # create a branch.
541
 
            transport = transport.clone('..')
 
551
            to_transport = to_transport.clone('..')
542
552
            if not create_prefix:
543
553
                try:
544
 
                    relurl = transport.relpath(location_url)
 
554
                    relurl = to_transport.relpath(location_url)
545
555
                    mutter('creating directory %s => %s', location_url, relurl)
546
 
                    transport.mkdir(relurl)
 
556
                    to_transport.mkdir(relurl)
547
557
                except NoSuchFile:
548
558
                    raise BzrCommandError("Parent directory of %s "
549
559
                                          "does not exist." % location)
550
560
            else:
551
 
                current = transport.base
552
 
                needed = [(transport, transport.relpath(location_url))]
 
561
                current = to_transport.base
 
562
                needed = [(to_transport, to_transport.relpath(location_url))]
553
563
                while needed:
554
564
                    try:
555
 
                        transport, relpath = needed[-1]
556
 
                        transport.mkdir(relpath)
 
565
                        to_transport, relpath = needed[-1]
 
566
                        to_transport.mkdir(relpath)
557
567
                        needed.pop()
558
568
                    except NoSuchFile:
559
 
                        new_transport = transport.clone('..')
 
569
                        new_transport = to_transport.clone('..')
560
570
                        needed.append((new_transport,
561
 
                                       new_transport.relpath(transport.base)))
562
 
                        if new_transport.base == transport.base:
 
571
                                       new_transport.relpath(to_transport.base)))
 
572
                        if new_transport.base == to_transport.base:
563
573
                            raise BzrCommandError("Could not create "
564
574
                                                  "path prefix.")
565
575
            dir_to = br_from.bzrdir.clone(location_url,
618
628
    aliases = ['get', 'clone']
619
629
 
620
630
    def run(self, from_location, to_location=None, revision=None, basis=None):
621
 
        from bzrlib.transport import get_transport
622
631
        if revision is None:
623
632
            revision = [None]
624
633
        elif len(revision) > 1:
651
660
            else:
652
661
                name = os.path.basename(to_location) + '\n'
653
662
 
654
 
            to_transport = get_transport(to_location)
 
663
            to_transport = transport.get_transport(to_location)
655
664
            try:
656
665
                to_transport.mkdir('.')
657
666
            except errors.FileExists:
800
809
    'bzr revert' instead of 'bzr commit' after the update.
801
810
    """
802
811
    takes_args = ['dir?']
 
812
    aliases = ['up']
803
813
 
804
814
    def run(self, dir='.'):
805
815
        tree = WorkingTree.open_containing(dir)[0]
1016
1026
            format = get_format_type('default')
1017
1027
        if location is None:
1018
1028
            location = u'.'
1019
 
        else:
1020
 
            # The path has to exist to initialize a
1021
 
            # branch inside of it.
1022
 
            # Just using os.mkdir, since I don't
1023
 
            # believe that we want to create a bunch of
1024
 
            # locations if the user supplies an extended path
1025
 
            if not os.path.exists(location):
1026
 
                os.mkdir(location)
 
1029
 
 
1030
        to_transport = transport.get_transport(location)
 
1031
 
 
1032
        # The path has to exist to initialize a
 
1033
        # branch inside of it.
 
1034
        # Just using os.mkdir, since I don't
 
1035
        # believe that we want to create a bunch of
 
1036
        # locations if the user supplies an extended path
 
1037
        # TODO: create-prefix
 
1038
        try:
 
1039
            to_transport.mkdir('.')
 
1040
        except errors.FileExists:
 
1041
            pass
 
1042
                    
1027
1043
        try:
1028
1044
            existing_bzrdir = bzrdir.BzrDir.open(location)
1029
1045
        except NotBranchError:
1031
1047
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
1032
1048
        else:
1033
1049
            if existing_bzrdir.has_branch():
1034
 
                if existing_bzrdir.has_workingtree():
1035
 
                    raise errors.AlreadyBranchError(location)
1036
 
                else:
1037
 
                    raise errors.BranchExistsWithoutWorkingTree(location)
 
1050
                if (isinstance(to_transport, LocalTransport)
 
1051
                    and not existing_bzrdir.has_workingtree()):
 
1052
                        raise errors.BranchExistsWithoutWorkingTree(location)
 
1053
                raise errors.AlreadyBranchError(location)
1038
1054
            else:
1039
1055
                existing_bzrdir.create_branch()
1040
1056
                existing_bzrdir.create_workingtree()
1066
1082
                             ' a working tree')]
1067
1083
    aliases = ["init-repo"]
1068
1084
    def run(self, location, format=None, trees=False):
1069
 
        from bzrlib.transport import get_transport
1070
1085
        if format is None:
1071
1086
            format = get_format_type('default')
1072
 
        transport = get_transport(location)
1073
 
        if not transport.has('.'):
1074
 
            transport.mkdir('')
1075
 
        newdir = format.initialize_on_transport(transport)
 
1087
 
 
1088
        if location is None:
 
1089
            location = '.'
 
1090
 
 
1091
        to_transport = transport.get_transport(location)
 
1092
        try:
 
1093
            to_transport.mkdir('.')
 
1094
        except errors.FileExists:
 
1095
            pass
 
1096
 
 
1097
        newdir = format.initialize_on_transport(to_transport)
1076
1098
        repo = newdir.create_repository(shared=True)
1077
1099
        repo.set_make_working_trees(trees)
1078
1100
 
1480
1502
        from bzrlib.atomicfile import AtomicFile
1481
1503
        if old_default_rules is not None:
1482
1504
            # dump the rules and exit
1483
 
            for pattern in bzrlib.DEFAULT_IGNORE:
 
1505
            for pattern in ignores.OLD_DEFAULTS:
1484
1506
                print pattern
1485
1507
            return
1486
1508
        if name_pattern is None:
2008
2030
 
2009
2031
class cmd_version(Command):
2010
2032
    """Show version of bzr."""
 
2033
 
2011
2034
    @display_command
2012
2035
    def run(self):
2013
2036
        show_version()
2014
2037
 
 
2038
 
2015
2039
class cmd_rocks(Command):
2016
2040
    """Statement of optimism."""
 
2041
 
2017
2042
    hidden = True
 
2043
 
2018
2044
    @display_command
2019
2045
    def run(self):
2020
2046
        print "it sure does!"
2021
2047
 
2022
2048
 
2023
2049
class cmd_find_merge_base(Command):
2024
 
    """Find and print a base revision for merging two branches.
2025
 
    """
 
2050
    """Find and print a base revision for merging two branches."""
2026
2051
    # TODO: Options to specify revisions on either side, as if
2027
2052
    #       merging only part of the history.
2028
2053
    takes_args = ['branch', 'other']
2395
2420
        if other_branch is None:
2396
2421
            other_branch = parent
2397
2422
            if other_branch is None:
2398
 
                raise BzrCommandError("No missing location known or specified.")
 
2423
                raise BzrCommandError("No peer location known or specified.")
2399
2424
            print "Using last location: " + local_branch.get_parent()
2400
2425
        remote_branch = Branch.open(other_branch)
2401
2426
        if remote_branch.base == local_branch.base: