/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: John Arbash Meinel
  • Date: 2009-07-09 15:18:57 UTC
  • mto: This revision was merged to the branch mainline in revision 4535.
  • Revision ID: john@arbash-meinel.com-20090709151857-0halwp51u1on5p1n
'bzr switch -b' can now be used to create the branch while you switch to it.

This is just a convenience thing, but it shortens:
  bzr branch . ../new-branch
  bzr switch ../new-branch
into a single:
  bzr switch -b ../new-branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
5299
5299
 
5300
5300
    takes_args = ['to_location']
5301
5301
    takes_options = [Option('force',
5302
 
                        help='Switch even if local commits will be lost.')
 
5302
                        help='Switch even if local commits will be lost.'),
 
5303
                     Option('create-branch', short_name='b',
 
5304
                        help='Create the target branch from this one before'
 
5305
                             ' switching to it.'),
5303
5306
                     ]
5304
5307
 
5305
 
    def run(self, to_location, force=False):
 
5308
    def run(self, to_location, force=False, create_branch=False):
5306
5309
        from bzrlib import switch
5307
5310
        tree_location = '.'
5308
5311
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5310
5313
            branch = control_dir.open_branch()
5311
5314
            had_explicit_nick = branch.get_config().has_explicit_nickname()
5312
5315
        except errors.NotBranchError:
 
5316
            branch = None
5313
5317
            had_explicit_nick = False
5314
 
        try:
5315
 
            to_branch = Branch.open(to_location)
5316
 
        except errors.NotBranchError:
5317
 
            this_url = self._get_branch_location(control_dir)
5318
 
            to_branch = Branch.open(
5319
 
                urlutils.join(this_url, '..', to_location))
 
5318
        if create_branch:
 
5319
            if branch is None:
 
5320
                raise errors.BzrCommandError('cannot create branch without'
 
5321
                                             ' source branch')
 
5322
            if '/' not in to_location and '\\' not in to_location:
 
5323
                # This path is meant to be relative to the existing branch
 
5324
                this_url = self._get_branch_location(control_dir)
 
5325
                to_location = urlutils.join(this_url, '..', to_location)
 
5326
            to_branch = branch.bzrdir.sprout(to_location,
 
5327
                                 possible_transports=[branch.bzrdir.root_transport],
 
5328
                                 source_branch=branch).open_branch()
 
5329
            # try:
 
5330
            #     from_branch = control_dir.open_branch()
 
5331
            # except errors.NotBranchError:
 
5332
            #     raise BzrCommandError('Cannot create a branch from this'
 
5333
            #         ' location when we cannot open this branch')
 
5334
            # from_branch.bzrdir.sprout(
 
5335
            pass
 
5336
        else:
 
5337
            try:
 
5338
                to_branch = Branch.open(to_location)
 
5339
            except errors.NotBranchError:
 
5340
                this_url = self._get_branch_location(control_dir)
 
5341
                to_branch = Branch.open(
 
5342
                    urlutils.join(this_url, '..', to_location))
5320
5343
        switch.switch(control_dir, to_branch, force)
5321
5344
        if had_explicit_nick:
5322
5345
            branch = control_dir.open_branch() #get the new branch!