def test_simple_serve(self):
     # 'serve' in a default format working tree shouldn't need many modules
     tree = self.make_branch_and_tree('.')
     # Capture the bzr serve process' stderr in a file to avoid deadlocks
     # while the smart client interacts with it.
     stderr_file = open('bzr-serve.stderr', 'w')
     process = self.start_bzr_subprocess_with_import_check(['serve',
         '--inet', '-d', tree.basedir], stderr_file=stderr_file)
     url = 'bzr://localhost/'
     self.permit_url(url)
     client_medium = medium.SmartSimplePipesClientMedium(
         process.stdout, process.stdin, url)
     transport = remote.RemoteTransport(url, medium=client_medium)
     branch = ControlDir.open_from_transport(transport).open_branch()
     process.stdin.close()
     # Hide stdin from the subprocess module, so it won't fail to close it.
     process.stdin = None
     (out, err) = self.finish_bzr_subprocess(process,
         universal_newlines=False)
     stderr_file.close()
     with open('bzr-serve.stderr', 'r') as stderr_file:
         err = stderr_file.read()
     self.check_forbidden_modules(err,
         ['bzrlib.annotate',
         'bzrlib.atomicfile',
         'bzrlib.bugtracker',
         'bzrlib.bundle.commands',
         'bzrlib.cmd_version_info',
         'bzrlib.dirstate',
         'bzrlib._dirstate_helpers_py',
         'bzrlib._dirstate_helpers_pyx',
         'bzrlib.externalcommand',
         'bzrlib.filters',
         'bzrlib.hashcache',
         # foreign branch plugins import the foreign_vcs_registry from 
         # bzrlib.foreign so it can't be blacklisted
         'bzrlib.gpg',
         'bzrlib.info',
         'bzrlib.knit',
         'bzrlib.merge3',
         'bzrlib.merge_directive',
         'bzrlib.msgeditor',
         'bzrlib.patiencediff',
         'bzrlib.remote',
         'bzrlib.rules',
         'bzrlib.sign_my_commits',
         'bzrlib.smart.client',
         'bzrlib.transform',
         'bzrlib.version_info_formats.format_rio',
         'bzrlib.workingtree_4',
         'bzrlib.xml_serializer',
         'bzrlib.xml8',
         'getpass',
         'kerberos',
         'smtplib',
         'tarfile',
         'tempfile',
         'termios',
         'tty',
         ] + old_format_modules)
Esempio n. 2
0
def do_push(br_from, location, overwrite):
    """Update a mirror of a branch.

    :param br_from: the source branch
    :param location: the location of the branch that you'd like to update
    :param overwrite: overwrite target location if it diverged
    :return: number of revisions pushed
    """
    revision_id = None
    to_transport = get_transport(location)
    try:
        dir_to = ControlDir.open_from_transport(to_transport)
    except errors.NotBranchError:
        dir_to = None

    if dir_to is None:
        try:
            br_to = br_from.create_clone_on_transport(
                to_transport, revision_id=revision_id)
        except errors.NoSuchFile:
            response = question_dialog(
                _i18n('Non existing parent directory'),
                _i18n("The parent directory (%s)\ndoesn't exist. Create?") %
                    location)
            if response == Gtk.ResponseType.OK:
                br_to = br_from.create_clone_on_transport(
                    to_transport, revision_id=revision_id, create_prefix=True)
            else:
                return _i18n("Push aborted.")
        push_result = create_push_result(br_from, br_to)
    else:
        push_result = dir_to.push_branch(br_from, revision_id, overwrite)
    message = create_push_message(br_from, push_result)
    return message
Esempio n. 3
0
    def test_bzr_serve_inet_readwrite(self):
        # Make a branch
        self.make_branch('.')

        process, transport = self.start_server_inet(['--allow-writes'])

        # We get a working branch, and can create a directory
        branch = ControlDir.open_from_transport(transport).open_branch()
        self.make_read_requests(branch)
        transport.mkdir('adir')
        self.assertInetServerShutsdownCleanly(process)
Esempio n. 4
0
    def test_bzr_serve_inet_readwrite(self):
        # Make a branch
        self.make_branch('.')

        process, transport = self.start_server_inet(['--allow-writes'])

        # We get a working branch, and can create a directory
        branch = ControlDir.open_from_transport(transport).open_branch()
        self.make_read_requests(branch)
        transport.mkdir('adir')
        self.assertInetServerShutsdownCleanly(process)
Esempio n. 5
0
 def test_commit_readonly_checkout(self):
     # https://bugs.launchpad.net/bzr/+bug/129701
     # "UnlockableTransport error trying to commit in checkout of readonly
     # branch"
     self.make_branch('master')
     master = ControlDir.open_from_transport(
         self.get_readonly_transport('master')).open_branch()
     master.create_checkout('checkout')
     out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
         retcode=3)
     self.assertContainsRe(err,
         r'^bzr: ERROR: Cannot lock.*readonly transport')
Esempio n. 6
0
 def test_commit_readonly_checkout(self):
     # https://bugs.launchpad.net/bzr/+bug/129701
     # "UnlockableTransport error trying to commit in checkout of readonly
     # branch"
     self.make_branch('master')
     master = ControlDir.open_from_transport(
         self.get_readonly_transport('master')).open_branch()
     master.create_checkout('checkout')
     out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
                             retcode=3)
     self.assertContainsRe(err,
                           r'^bzr: ERROR: Cannot lock.*readonly transport')
Esempio n. 7
0
 def test_bzr_serve_dhpss(self):
     # This is a smoke test that the server doesn't crash when run with
     # -Dhpss, and does drop some hpss logging to the file.
     self.make_branch('.')
     log_fname = os.getcwd() + '/server.log'
     self.overrideEnv('BZR_LOG', log_fname)
     process, transport = self.start_server_inet(['-Dhpss'])
     branch = ControlDir.open_from_transport(transport).open_branch()
     self.make_read_requests(branch)
     self.assertInetServerShutsdownCleanly(process)
     f = open(log_fname, 'rb')
     content = f.read()
     f.close()
     self.assertContainsRe(content, r'hpss request: \[[0-9-]+\]')
Esempio n. 8
0
 def test_bzr_serve_dhpss(self):
     # This is a smoke test that the server doesn't crash when run with
     # -Dhpss, and does drop some hpss logging to the file.
     self.make_branch('.')
     log_fname = os.getcwd() + '/server.log'
     self.overrideEnv('BZR_LOG', log_fname)
     process, transport = self.start_server_inet(['-Dhpss'])
     branch = ControlDir.open_from_transport(transport).open_branch()
     self.make_read_requests(branch)
     self.assertInetServerShutsdownCleanly(process)
     f = open(log_fname, 'rb')
     content = f.read()
     f.close()
     self.assertContainsRe(content, r'hpss request: \[[0-9-]+\]')
Esempio n. 9
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)
        controldir = ControlDir.open_from_transport(transport)
        if controldir.get_branch_reference() is not None:
            raise errors.NotBranchError(transport.base)
        branch = controldir.open_branch(ignore_fallbacks=True)
        return self.do_with_branch(branch, *args)
Esempio n. 10
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)
        controldir = ControlDir.open_from_transport(transport)
        if controldir.get_branch_reference() is not None:
            raise errors.NotBranchError(transport.base)
        branch = controldir.open_branch(ignore_fallbacks=True)
        return self.do_with_branch(branch, *args)
Esempio n. 11
0
 def readonly_repository(self, repo):
     relpath = urlutils.basename(repo.bzrdir.user_url.rstrip('/'))
     return ControlDir.open_from_transport(
         self.get_readonly_transport(relpath)).open_repository()