/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-07-14 16:27:40 UTC
  • mfrom: (4520.1.1 1.18-switch-branch)
  • Revision ID: pqm@pqm.ubuntu.com-20090714162740-3nro58lxslrcfyh4
(jam) Add 'bzr switch -b' to create the branch and switch to it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5324
5324
 
5325
5325
    takes_args = ['to_location']
5326
5326
    takes_options = [Option('force',
5327
 
                        help='Switch even if local commits will be lost.')
 
5327
                        help='Switch even if local commits will be lost.'),
 
5328
                     Option('create-branch', short_name='b',
 
5329
                        help='Create the target branch from this one before'
 
5330
                             ' switching to it.'),
5328
5331
                     ]
5329
5332
 
5330
 
    def run(self, to_location, force=False):
 
5333
    def run(self, to_location, force=False, create_branch=False):
5331
5334
        from bzrlib import switch
5332
5335
        tree_location = '.'
5333
5336
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5335
5338
            branch = control_dir.open_branch()
5336
5339
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5337
5340
        except errors.NotBranchError:
 
5341
            branch = None
5338
5342
            had_explicit_nick = False
5339
 
        try:
5340
 
            to_branch = Branch.open(to_location)
5341
 
        except errors.NotBranchError:
5342
 
            this_url = self._get_branch_location(control_dir)
5343
 
            to_branch = Branch.open(
5344
 
                urlutils.join(this_url, '..', to_location))
 
5343
        if create_branch:
 
5344
            if branch is None:
 
5345
                raise errors.BzrCommandError('cannot create branch without'
 
5346
                                             ' source branch')
 
5347
            if '/' not in to_location and '\\' not in to_location:
 
5348
                # This path is meant to be relative to the existing branch
 
5349
                this_url = self._get_branch_location(control_dir)
 
5350
                to_location = urlutils.join(this_url, '..', to_location)
 
5351
            to_branch = branch.bzrdir.sprout(to_location,
 
5352
                                 possible_transports=[branch.bzrdir.root_transport],
 
5353
                                 source_branch=branch).open_branch()
 
5354
            # try:
 
5355
            #     from_branch = control_dir.open_branch()
 
5356
            # except errors.NotBranchError:
 
5357
            #     raise BzrCommandError('Cannot create a branch from this'
 
5358
            #         ' location when we cannot open this branch')
 
5359
            # from_branch.bzrdir.sprout(
 
5360
            pass
 
5361
        else:
 
5362
            try:
 
5363
                to_branch = Branch.open(to_location)
 
5364
            except errors.NotBranchError:
 
5365
                this_url = self._get_branch_location(control_dir)
 
5366
                to_branch = Branch.open(
 
5367
                    urlutils.join(this_url, '..', to_location))
5345
5368
        switch.switch(control_dir, to_branch, force)
5346
5369
        if had_explicit_nick:
5347
5370
            branch = control_dir.open_branch() #get the new branch!