Esempio n. 1
0
    def test_sprout_into_colocated_leaves_workingtree(self):
        # a bzrdir can construct a branch and repository for itself.
        if not self.bzrdir_format.is_supported():
            # unsupported formats are not loopback testable
            # because the default open will not open them and
            # they may not be initializable.
            raise tests.TestNotApplicable('Control dir format not supported')
        if not self.bzrdir_format.supports_workingtrees:
            raise tests.TestNotApplicable(
                'Control dir format does not support working trees')
        from_tree = self.make_branch_and_tree('from')
        self.build_tree_contents([('from/foo', 'contents')])
        from_tree.add(['foo'])
        revid1 = from_tree.commit("rev1")
        self.build_tree_contents([('from/foo', 'new contents')])
        revid2 = from_tree.commit("rev2")
        try:
            other_branch = self.make_branch_and_tree("to")
        except errors.UninitializableFormat:
            raise tests.TestNotApplicable(
                'Control dir does not support creating new branches.')

        result = other_branch.controldir.push_branch(from_tree.branch,
                                                     revision_id=revid1)
        self.assertTrue(result.workingtree_updated)
        self.assertFileEqual('contents', 'to/foo')

        from_tree.controldir.sprout(urlutils.join_segment_parameters(
            other_branch.user_url, {"branch": "target"}),
                                    revision_id=revid2)
        active_branch = other_branch.controldir.open_branch(name="")
        self.assertEqual(revid1, active_branch.last_revision())
        to_branch = other_branch.controldir.open_branch(name="target")
        self.assertEqual(revid2, to_branch.last_revision())
        self.assertFileEqual('contents', 'to/foo')
Esempio n. 2
0
def full_branch_url(branch):
    """Get the full URL for a branch.

    Ideally this should just return Branch.user_url,
    but that currently exclude the branch name
    in some situations.
    """
    if branch.name is None:
        return branch.user_url
    url, params = urlutils.split_segment_parameters(branch.user_url)
    if branch.name != "":
        params["branch"] = urlutils.quote(branch.name, "")
    return urlutils.join_segment_parameters(url, params)
Esempio n. 3
0
 def test_sprout_into_colocated(self):
     # a bzrdir can construct a branch and repository for itself.
     if not self.bzrdir_format.is_supported():
         # unsupported formats are not loopback testable
         # because the default open will not open them and
         # they may not be initializable.
         raise tests.TestNotApplicable('Control dir format not supported')
     from_tree = self.make_branch_and_tree('from')
     revid = from_tree.commit("rev1")
     try:
         other_branch = self.make_branch("to")
     except errors.UninitializableFormat:
         raise tests.TestNotApplicable(
             'Control dir does not support creating new branches.')
     to_dir = from_tree.controldir.sprout(
         urlutils.join_segment_parameters(other_branch.user_url,
                                          {"branch": "target"}))
     to_branch = to_dir.open_branch(name="target")
     self.assertEqual(revid, to_branch.last_revision())
Esempio n. 4
0
    def look_up(self, name, url):
        if "/" in name:
            (name, version) = name.split("/", 1)
        else:
            version = None

        apt_pkg.init()

        # Older versions of apt_pkg don't have SourceRecords,
        # newer versions give a deprecation warning when using
        # GetPkgSrcRecords.
        try:
            sources = apt_pkg.SourceRecords()
        except AttributeError:
            sources = apt_pkg.GetPkgSrcRecords()

        urls = {}
        lookup = getattr(sources, 'lookup', None) or sources.Lookup
        while lookup(name):
            record = getattr(sources, 'record', None) or sources.Record
            for l in record.splitlines():
                if not ": " in l:
                    continue
                (field, value) = l.strip("\n").split(": ", 1)

                if field == "Version":
                    pkg_version = value
                elif field.startswith("X-Vcs-") or field.startswith("Vcs-"):
                    vcs = field.split("-")[-1]
                    urls.setdefault(pkg_version, {})[vcs] = value

        if len(urls) == 0:
            raise errors.InvalidURL(path=url, extra='no URLs found')

        if version is None:
            # Try the latest version
            cmp = getattr(apt_pkg, 'version_compare',
                          getattr(apt_pkg, 'VersionCompare', None))
            version = sorted(urls, cmp=cmp)[0]

        if not version in urls:
            raise errors.InvalidURL(path=url,
                                    extra='version %s not found' % version)

        note("Retrieving Vcs locating from %s Debian version %s", name,
             version)

        if "Bzr" in urls[version]:
            return urls[version]["Bzr"]

        if "Svn" in urls[version]:
            try:
                from .. import svn
            except ImportError:
                note("This package uses subversion. If you would like to "
                     "access it with bzr then please install brz-svn "
                     "and re-run the command.")
            else:
                return urls[version]["Svn"]

        if "Git" in urls[version]:
            try:
                from .. import git
            except ImportError:
                note("This package uses git. If you would like to "
                     "access it with bzr then please install brz-git "
                     "and re-run the command.")
            else:
                from breezy import urlutils
                url = urls[version]["Git"]
                if ' -b ' in url:
                    (url, branch) = url.split(' -b ', 1)
                    url = urlutils.join_segment_parameters(
                        url, {'branch': branch})
                return url

        if "Hg" in urls[version]:
            try:
                from .. import hg
            except ImportError:
                note("This package uses hg. If you would like to "
                     "access it with bzr then please install brz-hg"
                     "and re-run the command.")
            else:
                return urls[version]["Hg"]

        raise errors.InvalidURL(path=url,
                                extra='unsupported VCSes %r found' %
                                urls[version].keys())