~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
415
415
    takes_args = ['location?']
416
416
 
417
417
    def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
418
 
        # FIXME: too much stuff is in the command class        
419
 
        tree_to = WorkingTree.open_containing(u'.')[0]
420
 
        stored_loc = tree_to.branch.get_parent()
 
418
        # FIXME: too much stuff is in the command class
 
419
        try:
 
420
            tree_to = WorkingTree.open_containing(u'.')[0]
 
421
            branch_to = tree_to.branch
 
422
        except NoWorkingTree:
 
423
            tree_to = None
 
424
            branch_to = Branch.open_containing(u'.')[0] 
 
425
        stored_loc = branch_to.get_parent()
421
426
        if location is None:
422
427
            if stored_loc is None:
423
428
                raise BzrCommandError("No pull location known or specified.")
426
431
                location = stored_loc
427
432
 
428
433
        br_from = Branch.open(location)
429
 
        br_to = tree_to.branch
430
434
 
431
435
        if revision is None:
432
436
            rev_id = None
435
439
        else:
436
440
            raise BzrCommandError('bzr pull --revision takes one value.')
437
441
 
438
 
        old_rh = br_to.revision_history()
439
 
        count = tree_to.pull(br_from, overwrite, rev_id)
 
442
        old_rh = branch_to.revision_history()
 
443
        if tree_to is not None:
 
444
            count = tree_to.pull(br_from, overwrite, rev_id)
 
445
        else:
 
446
            count = branch_to.pull(br_from, overwrite, rev_id)
440
447
 
441
 
        if br_to.get_parent() is None or remember:
442
 
            br_to.set_parent(location)
 
448
        if branch_to.get_parent() is None or remember:
 
449
            branch_to.set_parent(location)
443
450
        note('%d revision(s) pulled.' % (count,))
444
451
 
445
452
        if verbose:
446
 
            new_rh = tree_to.branch.revision_history()
 
453
            new_rh = branch_to.revision_history()
447
454
            if old_rh != new_rh:
448
455
                # Something changed
449
456
                from bzrlib.log import show_changed_revisions
450
 
                show_changed_revisions(tree_to.branch, old_rh, new_rh)
 
457
                show_changed_revisions(branch_to, old_rh, new_rh)
451
458
 
452
459
 
453
460
class cmd_push(Command):
898
905
            # locations if the user supplies an extended path
899
906
            if not os.path.exists(location):
900
907
                os.mkdir(location)
 
908
        bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
909
 
 
910
 
 
911
class cmd_init_repository(Command):
 
912
    """Create a shared repository to keep branches in."""
 
913
    takes_args = ["location"] 
 
914
    takes_options = [Option('format', 
 
915
                            help='Use a specific format rather than the'
 
916
                            ' current default format. Currently this '
 
917
                            ' option only accepts "metadir" and "knit"',
 
918
                            type=get_format_type)]
 
919
    aliases = ["init-repo"]
 
920
    def run(self, location, format=None):
 
921
        from bzrlib.bzrdir import BzrDirMetaFormat1
 
922
        from bzrlib.transport import get_transport
901
923
        if format is None:
902
 
            # create default
903
 
            bzrdir.BzrDir.create_standalone_workingtree(location)
904
 
        else:
905
 
            new_dir = format.initialize(location)
906
 
            new_dir.create_repository()
907
 
            new_dir.create_branch()
908
 
            # TODO: ask the bzrdir format for the right classs
909
 
            import bzrlib.workingtree
910
 
            bzrlib.workingtree.WorkingTreeFormat3().initialize(new_dir)
 
924
            format = BzrDirMetaFormat1()
 
925
        get_transport(location).mkdir('')
 
926
        newdir = format.initialize(location)
 
927
        repo = newdir.create_repository(shared=True)
 
928
        repo.set_make_working_trees(False)
911
929
 
912
930
 
913
931
class cmd_diff(Command):