示例#1
0
 def test_locations(self):
     """Using and remembering different locations"""
     os.mkdir('a')
     os.chdir('a')
     self.run_bzr('init')
     self.run_bzr('commit -m unchanged --unchanged')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('merge', retcode=3)
     self.run_bzr('branch . ../b')
     os.chdir('../b')
     self.run_bzr('pull')
     self.run_bzr('branch . ../c')
     self.run_bzr('pull ../c')
     self.run_bzr('merge')
     os.chdir('../a')
     self.run_bzr('pull ../b')
     self.run_bzr('pull')
     self.run_bzr('pull ../c')
     self.run_bzr('branch ../c ../d')
     osutils.rmtree('../c')
     self.run_bzr('pull')
     os.chdir('../b')
     self.run_bzr('pull')
     os.chdir('../d')
     self.run_bzr('pull', retcode=3)
     self.run_bzr('pull ../a --remember')
     self.run_bzr('pull')
示例#2
0
    def merge_text(self, params):
        """Calls msgmerge when .po files conflict.

        This requires a valid .pot file to reconcile both sides.
        """
        # Create tmp files with the 'this' and 'other' content
        tmpdir = tempfile.mkdtemp(prefix='po_merge')
        env = {}
        env['this'] = osutils.pathjoin(tmpdir, 'this')
        env['other'] = osutils.pathjoin(tmpdir, 'other')
        env['result'] = osutils.pathjoin(tmpdir, 'result')
        env['pot_file'] = self.pot_file_abspath
        try:
            with osutils.open_file(env['this'], 'wb') as f:
                f.writelines(params.this_lines)
            with osutils.open_file(env['other'], 'wb') as f:
                f.writelines(params.other_lines)
            command = self.conf.expand_options(self.command, env)
            retcode, out, err = self._invoke(command)
            with osutils.open_file(env['result'], 'rb') as f:
                # FIXME: To avoid the list() construct below which means the
                # whole 'result' file is kept in memory, there may be a way to
                # use an iterator that will close the file when it's done, but
                # there is still the issue of removing the tmp dir...
                # -- vila 2011-11-24
                return 'success', list(f.readlines())
        finally:
            osutils.rmtree(tmpdir)
        return 'not applicable', []
示例#3
0
 def test_boundless_nick(self):
     """Nick defaults to implicit local nick when bound branch is AWOL"""
     base = self.make_branch_and_tree('base')
     child = self.make_branch_and_tree('child')
     self.run_bzr('bind ../base', working_dir='child')
     self.assertNick(base.branch.nick, working_dir='child', explicit=False)
     osutils.rmtree('base')
     self.assertNick('child', working_dir='child', explicit=False)
示例#4
0
    def test_no_autodelete_alternate_renamed(self):
        # Test for bug #114615
        tree_a = self.make_branch_and_tree('A')
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
        tree_a.add(['a', 'a/m', 'a/n'])
        tree_a.commit('init')

        tree_b = tree_a.controldir.sprout('B').open_workingtree()
        self.build_tree(['B/xyz/'])
        tree_b.add(['xyz'])
        tree_b.rename_one('a/m', 'xyz/m')
        osutils.rmtree('B/a')
        tree_b.commit('delete in B')

        self.assertThat(
            tree_b,
            HasPathRelations(tree_a, [('', ''), ('xyz/', None),
                                      ('xyz/m', 'a/m')]))

        self.build_tree_contents([('A/a/n', b'new contents for n\n')])
        tree_a.commit('change n in A')

        # Merging from A should introduce conflicts because 'n' was modified
        # (in A) and removed (in B), so 'a' needs to be restored.
        conflicts = tree_b.merge_from_branch(tree_a.branch)
        if tree_b.has_versioned_directories():
            self.assertEqual(3, len(conflicts))
        else:
            self.assertEqual(2, len(conflicts))

        self.assertThat(
            tree_b,
            HasPathRelations(tree_a, [('', ''), ('a/', 'a/'), ('xyz/', None),
                                      ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))

        osutils.rmtree('B/a')
        try:
            # bzr resolve --all
            tree_b.set_conflicts([])
        except errors.UnsupportedOperation:
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
            # effect.
            pass
        tree_b.commit('autoremove a, without touching xyz/m')

        self.assertThat(
            tree_b,
            HasPathRelations(tree_a, [('', ''), ('xyz/', None),
                                      ('xyz/m', 'a/m')]))
示例#5
0
    def test_no_autodelete_renamed_away(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'])
        rev_id1 = tree_a.commit('init')
        revtree = tree_a.branch.repository.revision_tree(rev_id1)
        # Rename one entry out of this directory
        tree_a.rename_one('dir/f1', 'dir2/a')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        # The only paths left should be the root
        self.assertThat(
            tree_a,
            HasPathRelations(revtree, [('', ''), ('dir2/', 'dir2/'),
                                       ('dir2/a', 'dir/f1')]))
示例#6
0
    def _remove_branches(self, removed_branches, exceptions):
        """Recursively remove a set of branches.

        :param removed_branches: Branches to remove recursively
        :param exceptions: Branches to *not* remove
        """
        # Remove removed branches
        for bp in removed_branches:
            skip = False
            for e in exceptions:
                if bp.startswith(e + "/"):
                    skip = True
                    break
            if skip:
                continue
            fullpath = self.to_transport.local_abspath(bp)
            if not os.path.isdir(fullpath):
                continue
            osutils.rmtree(fullpath)
示例#7
0
    def test_autodelete_renamed(self):
        tree_a = self.make_branch_and_tree('a')
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
        tree_a.add(['dir', 'dir/f1', 'dir/f2'])
        rev_id1 = tree_a.commit('init')
        # Start off by renaming entries,
        # but then actually auto delete the whole tree
        # https://bugs.launchpad.net/bzr/+bug/114615
        tree_a.rename_one('dir/f1', 'dir/a')
        tree_a.rename_one('dir/f2', 'dir/z')
        osutils.rmtree('a/dir')
        tree_a.commit('autoremoved')

        with tree_a.lock_read():
            paths = [(path, ie.file_id)
                     for path, ie in tree_a.iter_entries_by_dir()]
        # The only paths left should be the root
        if tree_a.supports_file_ids:
            self.assertEqual([('', tree_a.path2id(''))], paths)
示例#8
0
 def test_dir_changes_to_symlink(self):
     # <https://bugs.launchpad.net/bzr/+bug/192859>:
     # we had some past problems with the workingtree remembering for too
     # long what kind of object was at a particular name; we really
     # shouldn't do that.  Operating on the dirstate through passing
     # inventory deltas rather than mutating the inventory largely avoids
     # that.
     tree = self.make_branch_and_tree('tree')
     self.build_tree_contents([
         ('tree/a/',),
         ('tree/a/file', b'content'),
         ])
     tree.smart_add(['tree/a'])
     tree.commit('add dir')
     osutils.rmtree('tree/a')
     self.build_tree_contents([
         ('tree/a@', 'target'),
         ])
     tree.commit('change to symlink')
示例#9
0
    def run(self, from_location, to_location=None, format=None, trees=False,
            standalone=False, layout=None, all=False, prefix=None, keep=False,
            restore=False, until=None, colocated=False):
        from breezy import (
            osutils,
            trace,
            urlutils,
            )
        from breezy.controldir import ControlDir
        from breezy.errors import (
            BzrCommandError,
            NoRepositoryPresent,
            )
        from . import gettext
        from .convert import convert_repository
        from .remote import SvnRemoteAccess
        from .repository import SvnRepository
        from .workingtree import SvnCheckout
        import os
        from subvertpy import NODE_NONE

        if to_location is None:
            to_location = os.path.basename(from_location.rstrip("/\\"))

        if all:
            # All implies shared repository
            # (otherwise there is no repository to store revisions in)
            standalone = False

        if os.path.isfile(from_location):
            from .convert import load_dumpfile
            import tempfile
            tmp_repos = tempfile.mkdtemp(prefix='bzr-svn-dump-')
            load_dumpfile(from_location, tmp_repos)
            from_location = tmp_repos
        else:
            tmp_repos = None

        from_dir = ControlDir.open(from_location)

        if not (isinstance(from_dir, SvnRemoteAccess) or
                isinstance(from_dir, SvnCheckout)):
            raise BzrCommandError(gettext(
                "Source repository is not a Subversion repository."))

        try:
            from_repos = from_dir.open_repository()
        except NoRepositoryPresent:
            if prefix is not None:
                raise BzrCommandError(
                    gettext("Path inside repository specified "
                            "and --prefix specified"))
            from_repos = from_dir.find_repository(_ignore_branch_path=True)
            assert from_dir.root_transport.base.startswith(from_repos.base)
            prefix = from_dir.root_transport.base[
                len(from_repos.base):].strip("/")
            prefix = prefix.encode("utf-8")

        if not isinstance(from_repos, SvnRepository):
            raise BzrCommandError(
                    gettext("Not a Subversion repository: %s") % from_location)

        if until is None:
            to_revnum = from_repos.get_latest_revnum()
        else:
            to_revnum = min(until, from_repos.get_latest_revnum())

        with from_repos.lock_read():
            if prefix is not None:
                if layout is None:
                    overall_layout = from_repos.get_guessed_layout()
                else:
                    overall_layout = layout
                prefix = prefix.strip("/") + "/"
                if overall_layout.is_branch(prefix):
                    raise BzrCommandError(
                        gettext("%s appears to contain a branch. "
                                "For individual branches, use 'bzr branch'.") %
                        from_location)
                # FIXME: Hint about is_tag()
                elif overall_layout.is_branch_parent(prefix):
                    self.outf.write(
                        gettext("Importing branches with prefix %s\n") %
                        ("/" + urlutils.unescape_for_display(prefix,
                         self.outf.encoding)))
                else:
                    raise BzrCommandError(
                        gettext("The specified path is inside a branch. "
                                "Specify a different URL or a different "
                                "repository layout (see also "
                                "'bzr help svn-layout')."))

            if (prefix is not None and
                    from_repos.transport.check_path(prefix, to_revnum)
                    == NODE_NONE):
                raise BzrCommandError("Prefix %s does not exist" % prefix)

            def filter_branch(branch):
                if (prefix is not None and
                        not branch.get_branch_path().startswith(prefix)):
                    return False
                return True

            trace.note(gettext("Using repository layout: %s"),
                       layout or from_repos.get_layout())
            convert_repository(
                from_repos, to_location, layout,
                not standalone, trees, all, format=format,
                filter_branch=filter_branch, keep=keep,
                incremental=not restore, to_revnum=to_revnum, prefix=prefix,
                colocated=colocated, remember_parent=(tmp_repos is None))

            if tmp_repos is not None:
                osutils.rmtree(tmp_repos)
            if not trees:
                trace.note(
                    gettext("Use 'bzr checkout' to create a working tree in "
                            "the newly created branches."))
示例#10
0
 def change_kind():
     if osutils.file_kind(path) == "directory":
         osutils.rmtree(path)
     else:
         osutils.delete_any(path)
     make_after(path)
示例#11
0
 def test_find_repository_not_found(self):
     repos_url = self.make_client('d', 'dc')
     osutils.rmtree("d")
     self.assertRaises(NoRepositoryPresent,
                       lambda: ControlDir.open("dc").find_repository())