Ejemplo n.º 1
0
 def test_init(self):
     self.run_bzr("init-repo a")
     self.run_bzr("init --format=default a/b")
     dir = ControlDir.open('a')
     self.assertIs(dir.open_repository().is_shared(), True)
     self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
     bdir = ControlDir.open('a/b')
     bdir.open_branch()
     self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository)
     wt = bdir.open_workingtree()
Ejemplo n.º 2
0
 def test_init(self):
     self.run_bzr("init-repo a")
     self.run_bzr("init --format=default a/b")
     dir = ControlDir.open('a')
     self.assertIs(dir.open_repository().is_shared(), True)
     self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
     bdir = ControlDir.open('a/b')
     bdir.open_branch()
     self.assertRaises(errors.NoRepositoryPresent, bdir.open_repository)
     wt = bdir.open_workingtree()
Ejemplo n.º 3
0
    def test_symlinks(self):
        if has_symlinks() is False:
            return
        os.mkdir('branch')
        ControlDir.create_standalone_workingtree('branch')
        os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
        os.mkdir('no-die-please')
        self.assertPathExists('branch/die-please')
        os.mkdir('no-die-please/child')

        clean_tree('branch', unknown=True, no_prompt=True)
        self.assertPathExists('no-die-please')
        self.assertPathExists('no-die-please/child')
Ejemplo n.º 4
0
    def test_symlinks(self):
        if has_symlinks() is False:
            return
        os.mkdir('branch')
        ControlDir.create_standalone_workingtree('branch')
        os.symlink(os.path.realpath('no-die-please'), 'branch/die-please')
        os.mkdir('no-die-please')
        self.assertPathExists('branch/die-please')
        os.mkdir('no-die-please/child')

        clean_tree('branch', unknown=True, no_prompt=True)
        self.assertPathExists('no-die-please')
        self.assertPathExists('no-die-please/child')
Ejemplo n.º 5
0
def upgrade(url, format=None, clean_up=False, dry_run=False):
    """Upgrade locations to format.
 
    This routine wraps the smart_upgrade() routine with a nicer UI.
    In particular, it ensures all URLs can be opened before starting
    and reports a summary at the end if more than one upgrade was attempted.
    This routine is useful for command line tools. Other bzrlib clients
    probably ought to use smart_upgrade() instead.

    :param url: a URL of the locations to upgrade.
    :param format: the format to convert to or None for the best default
    :param clean-up: if True, the backup.bzr directory is removed if the
      upgrade succeeded for a given repo/branch/tree
    :param dry_run: show what would happen but don't actually do any upgrades
    :return: the list of exceptions encountered
    """
    control_dirs = [ControlDir.open_unsupported(url)]
    attempted, succeeded, exceptions = smart_upgrade(control_dirs,
        format, clean_up=clean_up, dry_run=dry_run)
    if len(attempted) > 1:
        attempted_count = len(attempted)
        succeeded_count = len(succeeded)
        failed_count = attempted_count - succeeded_count
        ui.ui_factory.note(
            gettext('\nSUMMARY: {0} upgrades attempted, {1} succeeded,'\
                    ' {2} failed').format(
                     attempted_count, succeeded_count, failed_count))
    return exceptions
Ejemplo n.º 6
0
    def follow_reference(self, url):
        """Get the branch-reference value at the specified url.

        This exists as a separate method only to be overriden in unit tests.
        """
        bzrdir = ControlDir.open(url, probers=self.probers)
        return bzrdir.get_branch_reference()
Ejemplo n.º 7
0
    def test_iter_deletable(self):
        """Files are selected for deletion appropriately"""
        os.mkdir('branch')
        tree = ControlDir.create_standalone_workingtree('branch')
        transport = tree.bzrdir.root_transport
        transport.put_bytes('.bzrignore', '*~\n*.pyc\n.bzrignore\n')
        transport.put_bytes('file.BASE', 'contents')
        tree.lock_write()
        try:
            self.assertEqual(len(list(iter_deletables(tree, unknown=True))), 1)
            transport.put_bytes('file', 'contents')
            transport.put_bytes('file~', 'contents')
            transport.put_bytes('file.pyc', 'contents')
            dels = sorted([r for a,r in iter_deletables(tree, unknown=True)])
            self.assertEqual(['file', 'file.BASE'], dels)

            dels = [r for a,r in iter_deletables(tree, detritus=True)]
            self.assertEqual(sorted(['file~', 'file.BASE']), dels)

            dels = [r for a,r in iter_deletables(tree, ignored=True)]
            self.assertEqual(sorted(['file~', 'file.pyc', '.bzrignore']),
                             dels)

            dels = [r for a,r in iter_deletables(tree, unknown=False)]
            self.assertEqual([], dels)
        finally:
            tree.unlock()
 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)
Ejemplo n.º 9
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
Ejemplo n.º 10
0
    def __init__(self, url=None, format=None, control_dir=None):
        """Convert a Bazaar control directory to a given format.

        Either the url or control_dir parameter must be given.

        :param url: the URL of the control directory or None if the
          control_dir is explicitly given instead
        :param format: the format to convert to or None for the default
        :param control_dir: the control directory or None if it is
          specified via the URL parameter instead
        """
        self.format = format
        # XXX: Change to cleanup
        warning_id = 'cross_format_fetch'
        saved_warning = warning_id in ui.ui_factory.suppressed_warnings
        if url is None and control_dir is None:
            raise AssertionError(
                "either the url or control_dir parameter must be set.")
        if control_dir is not None:
            self.bzrdir = control_dir
        else:
            self.bzrdir = ControlDir.open_unsupported(url)
        if isinstance(self.bzrdir, RemoteBzrDir):
            self.bzrdir._ensure_real()
            self.bzrdir = self.bzrdir._real_bzrdir
        if self.bzrdir.root_transport.is_readonly():
            raise errors.UpgradeReadonly
        self.transport = self.bzrdir.root_transport
        ui.ui_factory.suppressed_warnings.add(warning_id)
        try:
            self.convert()
        finally:
            if not saved_warning:
                ui.ui_factory.suppressed_warnings.remove(warning_id)
Ejemplo n.º 11
0
    def setup_tree(self):
        wt = ControlDir.create_standalone_workingtree('.')
        wt.commit("base A", allow_pointless=True, rev_id='A')
        wt.commit("base B", allow_pointless=True, rev_id='B')
        wt.commit("base C", allow_pointless=True, rev_id='C')

        return wt
Ejemplo n.º 12
0
    def test_iter_deletable(self):
        """Files are selected for deletion appropriately"""
        os.mkdir('branch')
        tree = ControlDir.create_standalone_workingtree('branch')
        transport = tree.bzrdir.root_transport
        transport.put_bytes('.bzrignore', '*~\n*.pyc\n.bzrignore\n')
        transport.put_bytes('file.BASE', 'contents')
        tree.lock_write()
        try:
            self.assertEqual(len(list(iter_deletables(tree, unknown=True))), 1)
            transport.put_bytes('file', 'contents')
            transport.put_bytes('file~', 'contents')
            transport.put_bytes('file.pyc', 'contents')
            dels = sorted([r for a, r in iter_deletables(tree, unknown=True)])
            self.assertEqual(['file', 'file.BASE'], dels)

            dels = [r for a, r in iter_deletables(tree, detritus=True)]
            self.assertEqual(sorted(['file~', 'file.BASE']), dels)

            dels = [r for a, r in iter_deletables(tree, ignored=True)]
            self.assertEqual(sorted(['file~', 'file.pyc', '.bzrignore']), dels)

            dels = [r for a, r in iter_deletables(tree, unknown=False)]
            self.assertEqual([], dels)
        finally:
            tree.unlock()
Ejemplo n.º 13
0
    def run(self, location=None, remember=False, directory=None,
            no_rebase=False, strict=None):
        from bzrlib import urlutils
        from bzrlib.controldir import ControlDir
        from bzrlib.errors import BzrCommandError, NoWorkingTree
        from bzrlib.workingtree import WorkingTree

        if directory is None:
            directory = "."
        try:
            source_wt = WorkingTree.open_containing(directory)[0]
            source_branch = source_wt.branch
        except NoWorkingTree:
            source_branch = Branch.open(directory)
            source_wt = None
        if source_wt is not None:
            source_wt.check_changed_or_out_of_date(
                strict, 'dpush_strict',
                more_error='Use --no-strict to force the push.',
                more_warning='Uncommitted changes will not be pushed.')
        stored_loc = source_branch.get_push_location()
        if location is None:
            if stored_loc is None:
                raise BzrCommandError(gettext("No push location known or specified."))
            else:
                display_url = urlutils.unescape_for_display(stored_loc,
                        self.outf.encoding)
                self.outf.write(
                       gettext("Using saved location: %s\n") % display_url)
                location = stored_loc

        controldir = ControlDir.open(location)
        target_branch = controldir.open_branch()
        target_branch.lock_write()
        try:
            try:
                push_result = source_branch.push(target_branch, lossy=True)
            except errors.LossyPushToSameVCS:
                raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy "
                    "push not necessary. Please use regular push.").format(
                    source_branch, target_branch))
            # We successfully created the target, remember it
            if source_branch.get_push_location() is None or remember:
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
                source_branch.set_push_location(target_branch.base)
            if not no_rebase:
                old_last_revid = source_branch.last_revision()
                source_branch.pull(target_branch, overwrite=True)
                new_last_revid = source_branch.last_revision()
                if source_wt is not None and old_last_revid != new_last_revid:
                    source_wt.lock_write()
                    try:
                        target = source_wt.branch.repository.revision_tree(
                            new_last_revid)
                        update_workingtree_fileids(source_wt, target)
                    finally:
                        source_wt.unlock()
            push_result.report(self.outf)
        finally:
            target_branch.unlock()
Ejemplo n.º 14
0
 def test_post_pull_bound_branch(self):
     # pulling to a bound branch should pass in the master branch to the
     # hook, allowing the correct number of emails to be sent, while still
     # allowing hooks that want to modify the target to do so to both
     # instances.
     target = self.make_to_branch('target')
     local = self.make_from_branch('local')
     try:
         local.bind(target)
     except errors.UpgradeRequired:
         # We can't bind this format to itself- typically it is the local
         # branch that doesn't support binding.  As of May 2007
         # remotebranches can't be bound.  Let's instead make a new local
         # branch of the default type, which does allow binding.
         # See https://bugs.launchpad.net/bzr/+bug/112020
         local = ControlDir.create_branch_convenience('local2')
         local.bind(target)
     source = self.make_from_branch('source')
     Branch.hooks.install_named_hook('post_pull',
         self.capture_post_pull_hook, None)
     local.pull(source)
     # with nothing there we should still get a notification, and
     # have both branches locked at the notification time.
     self.assertEqual([
         ('post_pull', source, local.base, target.base, 0, NULL_REVISION,
          0, NULL_REVISION, True, True, True)
         ],
         self.hook_calls)
Ejemplo n.º 15
0
 def test_post_pull_bound_branch(self):
     # pulling to a bound branch should pass in the master branch to the
     # hook, allowing the correct number of emails to be sent, while still
     # allowing hooks that want to modify the target to do so to both
     # instances.
     target = self.make_to_branch('target')
     local = self.make_from_branch('local')
     try:
         local.bind(target)
     except errors.UpgradeRequired:
         # We can't bind this format to itself- typically it is the local
         # branch that doesn't support binding.  As of May 2007
         # remotebranches can't be bound.  Let's instead make a new local
         # branch of the default type, which does allow binding.
         # See https://bugs.launchpad.net/bzr/+bug/112020
         local = ControlDir.create_branch_convenience('local2')
         local.bind(target)
     source = self.make_from_branch('source')
     Branch.hooks.install_named_hook('post_pull',
                                     self.capture_post_pull_hook, None)
     local.pull(source)
     # with nothing there we should still get a notification, and
     # have both branches locked at the notification time.
     self.assertEqual([('post_pull', source, local.base, target.base, 0,
                        NULL_REVISION, 0, NULL_REVISION, True, True, True)],
                      self.hook_calls)
Ejemplo n.º 16
0
    def follow_reference(self, url):
        """Get the branch-reference value at the specified url.

        This exists as a separate method only to be overriden in unit tests.
        """
        bzrdir = ControlDir.open(url, probers=self.probers)
        return bzrdir.get_branch_reference()
Ejemplo n.º 17
0
 def test_notification_on_branch_from_repository(self):
     out, err = self.run_bzr("init-repository -q a")
     self.assertEqual(out, "")
     self.assertEqual(err, "")
     dir = ControlDir.open('a')
     dir.open_repository() # there is a repository there
     e = self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertContainsRe(str(e), "location is a repository")
Ejemplo n.º 18
0
 def test_make_repository_quiet(self):
     out, err = self.run_bzr("init-repository a -q")
     self.assertEqual(out, "")
     self.assertEqual(err, "")
     dir = ControlDir.open('a')
     self.assertIs(dir.open_repository().is_shared(), True)
     self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
Ejemplo n.º 19
0
    def test_init_repo_existing_dir(self):
        """Make repo in existing directory.

        (Malone #38331)
        """
        out, err = self.run_bzr("init-repository .")
        dir = ControlDir.open('.')
        self.assertTrue(dir.open_repository())
Ejemplo n.º 20
0
 def prepare_simple_history(self):
     """Prepare and return a working tree with one commit of one file"""
     # Commit with modified file should say so
     wt = ControlDir.create_standalone_workingtree('.')
     self.build_tree(['hello.txt', 'extra.txt'])
     wt.add(['hello.txt'])
     wt.commit(message='added')
     return wt
Ejemplo n.º 21
0
 def test_branch(self):
     self.run_bzr("init-repo a")
     self.run_bzr("init --format=default a/b")
     self.run_bzr('branch a/b a/c')
     cdir = ControlDir.open('a/c')
     cdir.open_branch()
     self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
     cdir.open_workingtree()
Ejemplo n.º 22
0
 def prepare_simple_history(self):
     """Prepare and return a working tree with one commit of one file"""
     # Commit with modified file should say so
     wt = ControlDir.create_standalone_workingtree('.')
     self.build_tree(['hello.txt', 'extra.txt'])
     wt.add(['hello.txt'])
     wt.commit(message='added')
     return wt
Ejemplo n.º 23
0
 def test_branch(self):
     self.run_bzr("init-repo a")
     self.run_bzr("init --format=default a/b")
     self.run_bzr('branch a/b a/c')
     cdir = ControlDir.open('a/c')
     cdir.open_branch()
     self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
     cdir.open_workingtree()
Ejemplo n.º 24
0
 def test_notification_on_branch_from_repository(self):
     out, err = self.run_bzr("init-repository -q a")
     self.assertEqual(out, "")
     self.assertEqual(err, "")
     dir = ControlDir.open('a')
     dir.open_repository()  # there is a repository there
     e = self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertContainsRe(str(e), "location is a repository")
Ejemplo n.º 25
0
 def test_make_repository_quiet(self):
     out, err = self.run_bzr("init-repository a -q")
     self.assertEqual(out, "")
     self.assertEqual(err, "")
     dir = ControlDir.open('a')
     self.assertIs(dir.open_repository().is_shared(), True)
     self.assertRaises(errors.NotBranchError, dir.open_branch)
     self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
Ejemplo n.º 26
0
    def test_init_repo_existing_dir(self):
        """Make repo in existing directory.

        (Malone #38331)
        """
        out, err = self.run_bzr("init-repository .")
        dir = ControlDir.open('.')
        self.assertTrue(dir.open_repository())
Ejemplo n.º 27
0
 def convert(self, to_convert, pb):
     """See Converter.convert()."""
     self.bzrdir = to_convert
     pb = ui.ui_factory.nested_progress_bar()
     try:
         ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
         self._convert_to_prefixed()
         return ControlDir.open(self.bzrdir.user_url)
     finally:
         pb.finished()
Ejemplo n.º 28
0
 def convert(self, to_convert, pb):
     """See Converter.convert()."""
     self.bzrdir = to_convert
     pb = ui.ui_factory.nested_progress_bar()
     try:
         ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
         self._convert_to_prefixed()
         return ControlDir.open(self.bzrdir.user_url)
     finally:
         pb.finished()
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
 def test_verbose_commit_with_unknown(self):
     """Unknown files should not be listed by default in verbose output"""
     # Is that really the best policy?
     wt = ControlDir.create_standalone_workingtree('.')
     self.build_tree(['hello.txt', 'extra.txt'])
     wt.add(['hello.txt'])
     out,err = self.run_bzr('commit -m added')
     self.assertEqual('', out)
     self.assertContainsRe(err, '^Committing to: .*\n'
                           'added hello\.txt\n'
                           'Committed revision 1\.\n$')
Ejemplo n.º 31
0
 def make_parent_and_local_branches(self):
     # Create a 'parent' branch as the base
     self.parent_tree = ControlDir.create_standalone_workingtree("parent")
     self.build_tree_contents([("parent/file", "parent")])
     self.parent_tree.add("file")
     self.parent_tree.commit("first commit", rev_id="parent")
     # Branch 'local' from parent and do a change
     local_bzrdir = self.parent_tree.bzrdir.sprout("local")
     self.local_tree = local_bzrdir.open_workingtree()
     self.build_tree_contents([("local/file", "local")])
     self.local_tree.commit("second commit", rev_id="local")
Ejemplo n.º 32
0
 def make_parent_and_local_branches(self):
     # Create a 'parent' branch as the base
     self.parent_tree = ControlDir.create_standalone_workingtree('parent')
     self.build_tree_contents([('parent/file', 'parent')])
     self.parent_tree.add('file')
     self.parent_tree.commit('first commit', rev_id='parent')
     # Branch 'local' from parent and do a change
     local_bzrdir = self.parent_tree.bzrdir.sprout('local')
     self.local_tree = local_bzrdir.open_workingtree()
     self.build_tree_contents([('local/file', 'local')])
     self.local_tree.commit('second commit', rev_id='local')
Ejemplo n.º 33
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)
Ejemplo n.º 34
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')
Ejemplo n.º 35
0
    def test_make_repository(self):
        out, err = self.run_bzr("init-repository a")
        self.assertEqual(
            out, """Shared repository with trees (format: 2a)
Location:
  shared repository: a
""")
        self.assertEqual(err, "")
        dir = ControlDir.open('a')
        self.assertIs(dir.open_repository().is_shared(), True)
        self.assertRaises(errors.NotBranchError, dir.open_branch)
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
Ejemplo n.º 36
0
    def test_make_repository(self):
        out, err = self.run_bzr("init-repository a")
        self.assertEqual(out,
"""Shared repository with trees (format: 2a)
Location:
  shared repository: a
""")
        self.assertEqual(err, "")
        dir = ControlDir.open('a')
        self.assertIs(dir.open_repository().is_shared(), True)
        self.assertRaises(errors.NotBranchError, dir.open_branch)
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
Ejemplo n.º 37
0
 def test_resign_directory(self):
     """Test --directory option"""
     wt = ControlDir.create_standalone_workingtree('a')
     wt.commit("base A", allow_pointless=True, rev_id='A')
     wt.commit("base B", allow_pointless=True, rev_id='B')
     wt.commit("base C", allow_pointless=True, rev_id='C')
     repo = wt.branch.repository
     self.monkey_patch_gpg()
     self.run_bzr('re-sign --directory=a -r revid:A')
     self.assertEqualSignature(repo, 'A')
     self.run_bzr('re-sign -d a B')
     self.assertEqualSignature(repo, 'B')
Ejemplo n.º 38
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')
Ejemplo n.º 39
0
 def test_verbose_commit_with_unknown(self):
     """Unknown files should not be listed by default in verbose output"""
     # Is that really the best policy?
     wt = ControlDir.create_standalone_workingtree('.')
     self.build_tree(['hello.txt', 'extra.txt'])
     wt.add(['hello.txt'])
     out, err = self.run_bzr('commit -m added')
     self.assertEqual('', out)
     self.assertContainsRe(
         err, '^Committing to: .*\n'
         'added hello\.txt\n'
         'Committed revision 1\.\n$')
Ejemplo n.º 40
0
    def test_branch_tree(self):
        self.run_bzr("init-repo --trees a")
        self.run_bzr("init --format=default b")
        with file('b/hello', 'wt') as f: f.write('bar')
        self.run_bzr("add b/hello")
        self.run_bzr("commit -m bar b/hello")

        self.run_bzr('branch b a/c')
        cdir = ControlDir.open('a/c')
        cdir.open_branch()
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
        self.assertPathExists('a/c/hello')
        cdir.open_workingtree()
Ejemplo n.º 41
0
 def convert(self, to_convert, pb):
     """See Converter.convert()."""
     self.bzrdir = to_convert
     if pb is not None:
         warnings.warn(gettext("pb parameter to convert() is deprecated"))
     self.pb = ui.ui_factory.nested_progress_bar()
     try:
         ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
         if isinstance(self.bzrdir.transport, local.LocalTransport):
             self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
         self._convert_to_weaves()
         return ControlDir.open(self.bzrdir.user_url)
     finally:
         self.pb.finished()
Ejemplo n.º 42
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-]+\]')
Ejemplo n.º 43
0
    def setUp(self):
        super(TestSend, self).setUp()
        grandparent_tree = ControlDir.create_standalone_workingtree("grandparent")
        self.build_tree_contents([("grandparent/file1", "grandparent")])
        grandparent_tree.add("file1")
        grandparent_tree.commit("initial commit", rev_id="rev1")

        parent_bzrdir = grandparent_tree.bzrdir.sprout("parent")
        parent_tree = parent_bzrdir.open_workingtree()
        parent_tree.commit("next commit", rev_id="rev2")

        branch_tree = parent_tree.bzrdir.sprout("branch").open_workingtree()
        self.build_tree_contents([("branch/file1", "branch")])
        branch_tree.commit("last commit", rev_id="rev3")
Ejemplo n.º 44
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-]+\]')
Ejemplo n.º 45
0
    def test_branch_tree(self):
        self.run_bzr("init-repo --trees a")
        self.run_bzr("init --format=default b")
        with file('b/hello', 'wt') as f:
            f.write('bar')
        self.run_bzr("add b/hello")
        self.run_bzr("commit -m bar b/hello")

        self.run_bzr('branch b a/c')
        cdir = ControlDir.open('a/c')
        cdir.open_branch()
        self.assertRaises(errors.NoRepositoryPresent, cdir.open_repository)
        self.assertPathExists('a/c/hello')
        cdir.open_workingtree()
Ejemplo n.º 46
0
 def convert(self, to_convert, pb):
     """See Converter.convert()."""
     self.bzrdir = to_convert
     if pb is not None:
         warnings.warn(gettext("pb parameter to convert() is deprecated"))
     self.pb = ui.ui_factory.nested_progress_bar()
     try:
         ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
         if isinstance(self.bzrdir.transport, local.LocalTransport):
             self.bzrdir.get_workingtree_transport(None).delete(
                 'stat-cache')
         self._convert_to_weaves()
         return ControlDir.open(self.bzrdir.user_url)
     finally:
         self.pb.finished()
Ejemplo n.º 47
0
    def setUp(self):
        super(TestSend, self).setUp()
        grandparent_tree = ControlDir.create_standalone_workingtree(
            'grandparent')
        self.build_tree_contents([('grandparent/file1', 'grandparent')])
        grandparent_tree.add('file1')
        grandparent_tree.commit('initial commit', rev_id='rev1')

        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
        parent_tree = parent_bzrdir.open_workingtree()
        parent_tree.commit('next commit', rev_id='rev2')

        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
        self.build_tree_contents([('branch/file1', 'branch')])
        branch_tree.commit('last commit', rev_id='rev3')
Ejemplo n.º 48
0
 def test_switch_new_colocated(self):
     # Create a branch branch-1 that initially is a checkout of 'foo'
     # Use switch to create 'anotherbranch' which derives from that
     repo = self.make_repository('branch-1', format='development-colo')
     target_branch = repo.bzrdir.create_branch(name='foo')
     repo.bzrdir.set_branch_reference(target_branch)
     tree = repo.bzrdir.create_workingtree()
     self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
     tree.add('file-1')
     revid1 = tree.commit('rev1')
     self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
     bzrdir = ControlDir.open("branch-1")
     self.assertEqual(set([b.name for b in bzrdir.list_branches()]),
                      set(["foo", "anotherbranch"]))
     self.assertEqual(bzrdir.open_branch().name, "anotherbranch")
     self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
Ejemplo n.º 49
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)
Ejemplo n.º 50
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)
Ejemplo n.º 51
0
 def test_mode_0(self):
     """Test when a transport returns null permissions for .bzr"""
     if isinstance(self.branch_format, RemoteBranchFormat):
         # Remote branch format have no permission logic in them; there's
         # nothing to test here.
         raise tests.TestNotApplicable('Remote branches have no'
                                       ' permission logic')
     self.make_branch_and_tree('.')
     bzrdir = ControlDir.open('.')
     # Monkey patch the transport
     _orig_stat = bzrdir.transport.stat
     def null_perms_stat(*args, **kwargs):
         result = _orig_stat(*args, **kwargs)
         return _NullPermsStat(result)
     bzrdir.transport.stat = null_perms_stat
     self.assertIs(None, bzrdir._get_dir_mode())
     self.assertIs(None, bzrdir._get_file_mode())
Ejemplo n.º 52
0
 def test_switch_new_colocated(self):
     # Create a branch branch-1 that initially is a checkout of 'foo'
     # Use switch to create 'anotherbranch' which derives from that
     repo = self.make_repository('branch-1', format='development-colo')
     target_branch = repo.bzrdir.create_branch(name='foo')
     repo.bzrdir.set_branch_reference(target_branch)
     tree = repo.bzrdir.create_workingtree()
     self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
     tree.add('file-1')
     revid1 = tree.commit('rev1')
     self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
     bzrdir = ControlDir.open("branch-1")
     self.assertEquals(
         set([b.name for b in bzrdir.list_branches()]),
         set(["foo", "anotherbranch"]))
     self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
     self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
Ejemplo n.º 53
0
    def test_mode_0(self):
        """Test when a transport returns null permissions for .bzr"""
        if isinstance(self.branch_format, RemoteBranchFormat):
            # Remote branch format have no permission logic in them; there's
            # nothing to test here.
            raise tests.TestNotApplicable('Remote branches have no'
                                          ' permission logic')
        self.make_branch_and_tree('.')
        bzrdir = ControlDir.open('.')
        # Monkey patch the transport
        _orig_stat = bzrdir.transport.stat

        def null_perms_stat(*args, **kwargs):
            result = _orig_stat(*args, **kwargs)
            return _NullPermsStat(result)

        bzrdir.transport.stat = null_perms_stat
        self.assertIs(None, bzrdir._get_dir_mode())
        self.assertIs(None, bzrdir._get_file_mode())
Ejemplo n.º 54
0
    def test_content_filtering_applied_on_switch(self):
        # Create a source branch with two revisions
        source, fileid_1, fileid_2, fileid_3, fileid_4 = \
            self.create_cf_tree_with_two_revisions(txt_reader=None,
            txt_writer=None, dir='branch-a')
        if not source.supports_content_filtering():
            return

        # Now patch in content filtering and branch from revision 1
        self.patch_in_content_filter()
        self.run_bzr('branch -r1 branch-a branch-b')

        # Now create a lightweight checkout referring to branch-b
        self.run_bzr('checkout --lightweight branch-b checkout')
        self.assertFileEqual("fOO tXT", 'checkout/file1.txt')

        # Switch it to branch-b and check the tree is updated
        checkout_control_dir = ControlDir.open_containing('checkout')[0]
        switch(checkout_control_dir, source.branch)
        self.assertFileEqual("fOO rocks!", 'checkout/file1.txt')
        self.assertFileEqual("hELLO wORLD", 'checkout/file4.txt')
Ejemplo n.º 55
0
    def run(self,
            location=None,
            remember=False,
            directory=None,
            no_rebase=False,
            strict=None):
        from bzrlib import urlutils
        from bzrlib.controldir import ControlDir
        from bzrlib.errors import BzrCommandError, NoWorkingTree
        from bzrlib.workingtree import WorkingTree

        if directory is None:
            directory = "."
        try:
            source_wt = WorkingTree.open_containing(directory)[0]
            source_branch = source_wt.branch
        except NoWorkingTree:
            source_branch = Branch.open(directory)
            source_wt = None
        if source_wt is not None:
            source_wt.check_changed_or_out_of_date(
                strict,
                'dpush_strict',
                more_error='Use --no-strict to force the push.',
                more_warning='Uncommitted changes will not be pushed.')
        stored_loc = source_branch.get_push_location()
        if location is None:
            if stored_loc is None:
                raise BzrCommandError(
                    gettext("No push location known or specified."))
            else:
                display_url = urlutils.unescape_for_display(
                    stored_loc, self.outf.encoding)
                self.outf.write(
                    gettext("Using saved location: %s\n") % display_url)
                location = stored_loc

        controldir = ControlDir.open(location)
        target_branch = controldir.open_branch()
        target_branch.lock_write()
        try:
            try:
                push_result = source_branch.push(target_branch, lossy=True)
            except errors.LossyPushToSameVCS:
                raise BzrCommandError(
                    gettext(
                        "{0!r} and {1!r} are in the same VCS, lossy "
                        "push not necessary. Please use regular push.").format(
                            source_branch, target_branch))
            # We successfully created the target, remember it
            if source_branch.get_push_location() is None or remember:
                # FIXME: Should be done only if we succeed ? -- vila 2012-01-18
                source_branch.set_push_location(target_branch.base)
            if not no_rebase:
                old_last_revid = source_branch.last_revision()
                source_branch.pull(target_branch, overwrite=True)
                new_last_revid = source_branch.last_revision()
                if source_wt is not None and old_last_revid != new_last_revid:
                    source_wt.lock_write()
                    try:
                        target = source_wt.branch.repository.revision_tree(
                            new_last_revid)
                        update_workingtree_fileids(source_wt, target)
                    finally:
                        source_wt.unlock()
            push_result.report(self.outf)
        finally:
            target_branch.unlock()