~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: 2009-05-14 22:23:35 UTC
  • mfrom: (4354.2.2 switch2)
  • Revision ID: pqm@pqm.ubuntu.com-20090514222335-85rfl946254b3vk2
(abentley) lightweight checkouts with stale locations can be switched

Show diffs side-by-side

added added

removed removed

Lines of Context:
5304
5304
        from bzrlib import switch
5305
5305
        tree_location = '.'
5306
5306
        control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5307
 
        branch = control_dir.open_branch()
 
5307
        try:
 
5308
            branch = control_dir.open_branch()
 
5309
            had_explicit_nick = branch.get_config().has_explicit_nickname()
 
5310
        except errors.NotBranchError:
 
5311
            had_explicit_nick = False
5308
5312
        try:
5309
5313
            to_branch = Branch.open(to_location)
5310
5314
        except errors.NotBranchError:
5311
 
            this_branch = control_dir.open_branch()
5312
 
            # This may be a heavy checkout, where we want the master branch
5313
 
            this_url = this_branch.get_bound_location()
5314
 
            # If not, use a local sibling
5315
 
            if this_url is None:
5316
 
                this_url = this_branch.base
 
5315
            this_url = self._get_branch_location(control_dir)
5317
5316
            to_branch = Branch.open(
5318
5317
                urlutils.join(this_url, '..', to_location))
5319
5318
        switch.switch(control_dir, to_branch, force)
5320
 
        if branch.get_config().has_explicit_nickname():
 
5319
        if had_explicit_nick:
5321
5320
            branch = control_dir.open_branch() #get the new branch!
5322
5321
            branch.nick = to_branch.nick
5323
5322
        note('Switched to branch: %s',
5324
5323
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5325
5324
 
 
5325
    def _get_branch_location(self, control_dir):
 
5326
        """Return location of branch for this control dir."""
 
5327
        try:
 
5328
            this_branch = control_dir.open_branch()
 
5329
            # This may be a heavy checkout, where we want the master branch
 
5330
            master_location = this_branch.get_bound_location()
 
5331
            if master_location is not None:
 
5332
                return master_location
 
5333
            # If not, use a local sibling
 
5334
            return this_branch.base
 
5335
        except errors.NotBranchError:
 
5336
            format = control_dir.find_branch_format()
 
5337
            if getattr(format, 'get_reference', None) is not None:
 
5338
                return format.get_reference(control_dir)
 
5339
            else:
 
5340
                return control_dir.root_transport.base
 
5341
 
5326
5342
 
5327
5343
class cmd_view(Command):
5328
5344
    """Manage filtered views.