~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-15 04:49:48 UTC
  • mfrom: (3984.5.22 switch-r-183559)
  • Revision ID: pqm@pqm.ubuntu.com-20100115044948-yxz5m3vchxapbq22
(andrew) Add --revision option to 'bzr switch'. (#184559)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5437
5437
    that of the master.
5438
5438
    """
5439
5439
 
5440
 
    takes_args = ['to_location']
 
5440
    takes_args = ['to_location?']
5441
5441
    takes_options = [Option('force',
5442
5442
                        help='Switch even if local commits will be lost.'),
 
5443
                     'revision',
5443
5444
                     Option('create-branch', short_name='b',
5444
5445
                        help='Create the target branch from this one before'
5445
5446
                             ' switching to it.'),
5446
 
                     ]
 
5447
                    ]
5447
5448
 
5448
 
    def run(self, to_location, force=False, create_branch=False):
 
5449
    def run(self, to_location=None, force=False, create_branch=False,
 
5450
            revision=None):
5449
5451
        from bzrlib import switch
5450
5452
        tree_location = '.'
 
5453
        revision = _get_one_revision('switch', revision)
5451
5454
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
 
5455
        if to_location is None:
 
5456
            if revision is None:
 
5457
                raise errors.BzrCommandError('You must supply either a'
 
5458
                                             ' revision or a location')
 
5459
            to_location = '.'
5452
5460
        try:
5453
5461
            branch = control_dir.open_branch()
5454
5462
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5468
5476
            to_branch = branch.bzrdir.sprout(to_location,
5469
5477
                                 possible_transports=[branch.bzrdir.root_transport],
5470
5478
                                 source_branch=branch).open_branch()
5471
 
            # try:
5472
 
            #     from_branch = control_dir.open_branch()
5473
 
            # except errors.NotBranchError:
5474
 
            #     raise BzrCommandError('Cannot create a branch from this'
5475
 
            #         ' location when we cannot open this branch')
5476
 
            # from_branch.bzrdir.sprout(
5477
 
            pass
5478
5479
        else:
5479
5480
            try:
5480
5481
                to_branch = Branch.open(to_location)
5482
5483
                this_url = self._get_branch_location(control_dir)
5483
5484
                to_branch = Branch.open(
5484
5485
                    urlutils.join(this_url, '..', to_location))
5485
 
        switch.switch(control_dir, to_branch, force)
 
5486
        if revision is not None:
 
5487
            revision = revision.as_revision_id(to_branch)
 
5488
        switch.switch(control_dir, to_branch, force, revision_id=revision)
5486
5489
        if had_explicit_nick:
5487
5490
            branch = control_dir.open_branch() #get the new branch!
5488
5491
            branch.nick = to_branch.nick