Example #1
0
 def redirected(transport, e, redirection_notice):
     self.policy.checkOneURL(e.target)
     redirected_transport = transport._redirected_to(e.source, e.target)
     if redirected_transport is None:
         raise errors.NotBranchError(e.source)
     trace.note('%s is%s redirected to %s', transport.base,
                e.permanently, redirected_transport.base)
     return redirected_transport
Example #2
0
 def test_format_exception(self):
     """Short formatting of bzr exceptions"""
     try:
         raise errors.NotBranchError('wibble')
     except errors.NotBranchError:
         pass
     msg = _format_exception()
     self.assertTrue(len(msg) > 0)
     self.assertEqualDiff(msg, 'bzr: ERROR: Not a branch: \"wibble\".\n')
Example #3
0
    def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
        class FakeBzrDir(object):
            def open_repository(self):
                # str() on the NotBranchError will trigger a call to this,
                # which in turn will another, identical NotBranchError.
                raise errors.NotBranchError('path', bzrdir=FakeBzrDir())

        err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
        self.assertEqual('Not a branch: "path".', str(err))
Example #4
0
 def find_format(transport):
     last_error = errors.NotBranchError(transport.base)
     for prober_kls in self.probers:
         prober = prober_kls()
         try:
             return transport, prober.probe_transport(transport)
         except errors.NotBranchError as e:
             last_error = e
     else:
         raise last_error
Example #5
0
    def do(self, path, *args):
        """Execute a request for a branch at path.
    
        All Branch requests take a path to the branch as their first argument.

        If the branch is a branch reference, NotBranchError is raised.

        :param path: The path for the repository as received from the
            client.
        :return: A SmartServerResponse from self.do_with_branch().
        """
        transport = self.transport_from_client_path(path)
        bzrdir = BzrDir.open_from_transport(transport)
        if bzrdir.get_branch_reference() is not None:
            raise errors.NotBranchError(transport.base)
        branch = bzrdir.open_branch()
        return self.do_with_branch(branch, *args)
Example #6
0
    def test_not_branch_laziness(self):
        real_bzrdir = self.make_bzrdir('path')

        class FakeBzrDir(object):
            def __init__(self):
                self.calls = []

            def open_repository(self):
                self.calls.append('open_repository')
                raise errors.NoRepositoryPresent(real_bzrdir)

        fake_bzrdir = FakeBzrDir()
        err = errors.NotBranchError('path', bzrdir=fake_bzrdir)
        self.assertEqual([], fake_bzrdir.calls)
        str(err)
        self.assertEqual(['open_repository'], fake_bzrdir.calls)
        # Stringifying twice doesn't try to open a repository twice.
        str(err)
        self.assertEqual(['open_repository'], fake_bzrdir.calls)
 def open(self,
          a_bzrdir,
          name=None,
          _found=False,
          ignore_fallbacks=False,
          found_repository=None):
     if name is None:
         name = a_bzrdir._get_selected_branch()
     if not _found:
         raise NotImplementedError
     try:
         transport = a_bzrdir.get_branch_transport(None, name=name)
         control_files = lockable_files.LockableFiles(
             transport, 'lock', lockdir.LockDir)
         if found_repository is None:
             found_repository = a_bzrdir.find_repository()
         return DummyForeignVcsBranch(_format=self,
                                      _control_files=control_files,
                                      a_bzrdir=a_bzrdir,
                                      _repository=found_repository,
                                      name=name)
     except errors.NoSuchFile:
         raise errors.NotBranchError(path=transport.base)
 def probe_transport(klass, transport):
     """Return the .bzrdir style format present in a directory."""
     if not transport.has('.dummy'):
         raise errors.NotBranchError(path=transport.base)
     return DummyForeignVcsDirFormat()
Example #9
0
    def mirror(self):
        """Open source and destination branches and pull source into
        destination.
        """
        self.protocol.startMirroring()
        try:
            dest_branch, revid_before, stacked_on_url = \
                self.mirrorWithoutChecks()
        # add further encountered errors from the production runs here
        # ------ HERE ---------
        #
        except urllib2.HTTPError as e:
            msg = str(e)
            if int(e.code) == httplib.UNAUTHORIZED:
                # Maybe this will be caught in bzrlib one day, and then we'll
                # be able to get rid of this.
                # https://launchpad.net/products/bzr/+bug/42383
                msg = "Authentication required."
            self._mirrorFailed(msg)

        except socket.error as e:
            msg = 'A socket error occurred: %s' % str(e)
            self._mirrorFailed(msg)

        except errors.UnsupportedFormatError as e:
            msg = ("Launchpad does not support branches from before "
                   "bzr 0.7. Please upgrade the branch using bzr upgrade.")
            self._mirrorFailed(msg)

        except errors.UnknownFormatError as e:
            self._mirrorFailed(e)

        except (errors.ParamikoNotPresent, BadUrlSsh) as e:
            msg = ("Launchpad cannot mirror branches from SFTP and SSH URLs."
                   " Please register a HTTP location for this branch.")
            self._mirrorFailed(msg)

        except BadUrlLaunchpad:
            msg = "Launchpad does not mirror branches from Launchpad."
            self._mirrorFailed(msg)

        except BadUrlScheme as e:
            msg = "Launchpad does not mirror %s:// URLs." % e.scheme
            self._mirrorFailed(msg)

        except errors.NotBranchError as e:
            hosted_branch_error = errors.NotBranchError(
                "lp:%s" % self.unique_name)
            message_by_type = {
                BranchType.HOSTED: str(hosted_branch_error),
                BranchType.IMPORTED: "Not a branch.",
                }
            msg = message_by_type.get(self.branch_type, str(e))
            self._mirrorFailed(msg)

        except BranchReferenceForbidden as e:
            msg = ("Branch references are not allowed for branches of type "
                   "%s." % (self.branch_type.title,))
            self._mirrorFailed(msg)

        except BranchLoopError as e:
            msg = "Circular branch reference."
            self._mirrorFailed(msg)

        except errors.BzrError as e:
            self._mirrorFailed(e)

        except InvalidURIError as e:
            self._mirrorFailed(e)

        except (KeyboardInterrupt, SystemExit):
            # Do not record OOPS for those exceptions.
            raise

        else:
            revid_after = dest_branch.last_revision()
            # XXX: Aaron Bentley 2008-06-13
            # Bazaar does not provide a public API for learning about
            # format markers.  Fix this in Bazaar, then here.
            control_string = dest_branch.bzrdir._format.get_format_string()
            if dest_branch._format.__class__ is BzrBranchFormat4:
                branch_string = BranchFormat.BZR_BRANCH_4.title
            else:
                branch_string = dest_branch._format.get_format_string()
            repository_format = dest_branch.repository._format
            if repository_format.__class__ is RepositoryFormat6:
                repository_string = RepositoryFormat.BZR_REPOSITORY_6.title
            elif repository_format.__class__ is RepositoryFormat5:
                repository_string = RepositoryFormat.BZR_REPOSITORY_5.title
            elif repository_format.__class__ is RepositoryFormat4:
                repository_string = RepositoryFormat.BZR_REPOSITORY_4.title
            else:
                repository_string = repository_format.get_format_string()
            self.protocol.branchChanged(
                stacked_on_url, revid_before, revid_after, control_string,
                branch_string, repository_string)
Example #10
0
 def open_repository(self):
     # str() on the NotBranchError will trigger a call to this,
     # which in turn will another, identical NotBranchError.
     raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
Example #11
0
 def test_not_branch_bzrdir_without_repo(self):
     bzrdir = self.make_bzrdir('bzrdir')
     err = errors.NotBranchError('path', bzrdir=bzrdir)
     self.assertEqual('Not a branch: "path".', str(err))
Example #12
0
 def test_not_branch_bzrdir_with_repo(self):
     bzrdir = self.make_repository('repo').bzrdir
     err = errors.NotBranchError('path', bzrdir=bzrdir)
     self.assertEqual('Not a branch: "path": location is a repository.',
                      str(err))
Example #13
0
 def test_not_branch_no_args(self):
     err = errors.NotBranchError('path')
     self.assertEqual('Not a branch: "path".', str(err))