Example #1
0
 def test_fetch_pack_none(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     out = BytesIO()
     walker = MemoryRepo().get_graph_walker()
     ret = c.fetch_pack(
         s.path,
         lambda heads: [b"a90fa2d900a17e99b433217e988c4eb4a2e9a097"],
         graph_walker=walker,
         pack_data=out.write)
     self.assertEqual({b'HEAD': b'refs/heads/master'}, ret.symrefs)
     self.assertEqual(
         {
             b'HEAD':
             b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
             b'refs/heads/master':
             b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
             b'refs/tags/mytag':
             b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
             b'refs/tags/mytag-packed':
             b'b0931cadc54336e78a1d980420e3268903b57a50'
         }, ret.refs)
     # Hardcoding is not ideal, but we'll fix that some other day..
     self.assertTrue(
         out.getvalue().startswith(b'PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
Example #2
0
 def test_fetch_empty(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     out = BytesIO()
     walker = {}
     ret = c.fetch_pack(s.path,
                        lambda heads: [],
                        graph_walker=walker,
                        pack_data=out.write)
     self.assertEqual(
         {
             b'HEAD':
             b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
             b'refs/heads/master':
             b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
             b'refs/tags/mytag':
             b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
             b'refs/tags/mytag-packed':
             b'b0931cadc54336e78a1d980420e3268903b57a50'
         }, ret.refs)
     self.assertEqual({b'HEAD': b'refs/heads/master'}, ret.symrefs)
     self.assertEqual(
         b"PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08"
         b"\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e",
         out.getvalue())
Example #3
0
 def test_fetch_empty(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     out = BytesIO()
     walker = {}
     c.fetch_pack(s.path, lambda heads: [], graph_walker=walker,
         pack_data=out.write)
     self.assertEquals("PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08"
         "\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
Example #4
0
 def test_fetch_empty(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     out = BytesIO()
     walker = {}
     c.fetch_pack(s.path, lambda heads: [], graph_walker=walker,
         pack_data=out.write)
     self.assertEqual("PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08"
         "\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
Example #5
0
 def test_fetch_pack_none(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     out = StringIO()
     walker = MemoryRepo().get_graph_walker()
     c.fetch_pack(s.path,
         lambda heads: ["a90fa2d900a17e99b433217e988c4eb4a2e9a097"],
         graph_walker=walker, pack_data=out.write)
     # Hardcoding is not ideal, but we'll fix that some other day..
     self.assertEquals(out.getvalue(), 'PACK\x00\x00\x00\x02\x00\x00\x00\x07\x90\x0cx\x9c\xa5\xccM\n\xc20\x10@\xe1}N1\xfb\x82$v\xe2$ \xa2[/\xe0z\xd2\x19\xb1\x85\xa4\xd0\x8e\x14o\xef\xcf\x15|\xcbo\xf1lQ\x05\x92\xcc\x9e\x842\xc5\x1c\xf5\x1eB\x8f\x181\x97$>\x85\x9c\x14\xd3\x10b\x7f@\xc7O{\xcc\x0b\\\xb9\xea\n7]\xad\xbc\xe08m\x9dh\x19\xb9\x9d\xa7\xafo?\xde5\xb5\x13\x84@H\x14\xfd>C\xe7?\xb9a\xaeu4\xd3\x7f\x1e\xee"\x02\x0c\xdc\x04\x8a{\x03\x1a4:\\\x9a\x0ex\x9c\xa5\xccM\n\xc3 \x10@\xe1\xbd\xa7p\x1f(j\x1cG\xa1\x94v\xdb\x0bt=:#M II,\xa1\xb7\xef\xcf\x15\xfa\x96\xdf\xe2\xb5UD\xd7\xca\x1e\xd9C\xf4@\xb1\x06\xc0\xe0\x93\x15+\x9c\x13J_%P\x04#X\xd5\x83V\x99\x9bv\x84\x8e\x93K!\xb9\xe2-G\x00_\x0c\xd6\xd0\x1b\x8b\x80\x99l\xa4\x00\x9c\xac\xa2g\xbb/\xab\xbe\xd2$\x9b\xbe\xc9\xd6\xf2K\x1f\xc7\xbdc\xc9\x03\xcd\xe7\xf1\xeb\xfb\x8f\x0f\xb3\xb4\x93\xb6\x16="\x18\x8f\xba3\x9fTY\xa6ihM\xfey\xa8\x0b\xb3.\xea\rM\xb6F\x9c\xaa\x03x\x9c340031QHd\xf0\xfb\xcc\xbd\xffQ\x8a\xe1\xb29\x16\n\x97\x975\xdf\x0f\xb9\xd6\xf1\xe9\x8d!D2\x89\xc1_/US\xc1j\xd9\x15\xef\xa8o\x8f5u\x9ak\xde.`\xfe\t\x00\x97P\x18#7x\x9cK\xcb\xccIUH\xe4\x02\x00\n#\x02,7x\x9cK\xcb\xccIUH\xe2\x02\x00\n%\x02-\xa7\x05x\x9c340031QHd\xf0\xfb\xcc\xbd\xffQ\x8a\xe1\xb29\x16\n\x97\x975\xdf\x0f\xb9\xd6\xf1\xe9\x8d!D2\x89\xc1_/US\xc1j\xd9\x15\xef\xa8o\x8f5u\x9ak\xde.`\xfe\t\x95LfX4\xed\xc2\xeeD\xc1\x8eS\xbbU3%?g\x1ff\x14?\xb3\x80\x15\x00\xec0#h7x\x9cK\xcb\xccIUH\xe6\x02\x00\n\'\x02.\x8d7\x98\xae\xef7L\x95\x18\x94\x80X\xf1Q\xfb\xdc\xd9\xcf\xe7\xc3')
Example #6
0
 def test_fetch_pack_none(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     out = BytesIO()
     walker = MemoryRepo().get_graph_walker()
     c.fetch_pack(s.path,
         lambda heads: ["a90fa2d900a17e99b433217e988c4eb4a2e9a097"],
         graph_walker=walker, pack_data=out.write)
     # Hardcoding is not ideal, but we'll fix that some other day..
     self.assertTrue(out.getvalue().startswith('PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
Example #7
0
 def test_fetch_pack_none(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     out = BytesIO()
     walker = MemoryRepo().get_graph_walker()
     c.fetch_pack(s.path,
         lambda heads: ["a90fa2d900a17e99b433217e988c4eb4a2e9a097"],
         graph_walker=walker, pack_data=out.write)
     # Hardcoding is not ideal, but we'll fix that some other day..
     self.assertTrue(out.getvalue().startswith('PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
Example #8
0
    def pull(self, wire, url, apply_refs=True, refs=None, update_after=False):
        if url != 'default' and '://' not in url:
            client = LocalGitClient(url)
        else:
            url_obj = url_parser(url)
            o = self._build_opener(url)
            url, _ = url_obj.authinfo()
            client = HttpGitClient(base_url=url, opener=o)
        repo = self._factory.repo(wire)

        determine_wants = repo.object_store.determine_wants_all
        if refs:

            def determine_wants_requested(references):
                return [references[r] for r in references if r in refs]

            determine_wants = determine_wants_requested

        try:
            remote_refs = client.fetch(path=url,
                                       target=repo,
                                       determine_wants=determine_wants)
        except NotGitRepository as e:
            log.warning(
                'Trying to fetch from "%s" failed, not a Git repository.', url)
            # Exception can contain unicode which we convert
            raise exceptions.AbortException(e)(repr(e))

        # mikhail: client.fetch() returns all the remote refs, but fetches only
        # refs filtered by `determine_wants` function. We need to filter result
        # as well
        if refs:
            remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs}

        if apply_refs:
            # TODO: johbo: Needs proper test coverage with a git repository
            # that contains a tag object, so that we would end up with
            # a peeled ref at this point.
            for k in remote_refs:
                if k.endswith(PEELED_REF_MARKER):
                    log.debug("Skipping peeled reference %s", k)
                    continue
                repo[k] = remote_refs[k]

            if refs and not update_after:
                # mikhail: explicitly set the head to the last ref.
                repo['HEAD'] = remote_refs[refs[-1]]

        if update_after:
            # we want to checkout HEAD
            repo["HEAD"] = remote_refs["HEAD"]
            index.build_index_from_tree(repo.path, repo.index_path(),
                                        repo.object_store, repo["HEAD"].tree)
        return remote_refs
Example #9
0
    def fetch(self, wire, url, apply_refs=True, refs=None):
        if url != 'default' and '://' not in url:
            client = LocalGitClient(url)
        else:
            url_obj = hg_url(url)
            o = self._build_opener(url)
            url, _ = url_obj.authinfo()
            client = HttpGitClient(base_url=url, opener=o)
        repo = self._factory.repo(wire)

        determine_wants = repo.object_store.determine_wants_all
        if refs:

            def determine_wants_requested(references):
                return [references[r] for r in references if r in refs]

            determine_wants = determine_wants_requested

        try:
            remote_refs = client.fetch(path=url,
                                       target=repo,
                                       determine_wants=determine_wants)
        except NotGitRepository:
            log.warning(
                'Trying to fetch from "%s" failed, not a Git repository.', url)
            raise exceptions.AbortException()

        # mikhail: client.fetch() returns all the remote refs, but fetches only
        # refs filtered by `determine_wants` function. We need to filter result
        # as well
        if refs:
            remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs}

        if apply_refs:
            # TODO: johbo: Needs proper test coverage with a git repository
            # that contains a tag object, so that we would end up with
            # a peeled ref at this point.
            PEELED_REF_MARKER = '^{}'
            for k in remote_refs:
                if k.endswith(PEELED_REF_MARKER):
                    log.info("Skipping peeled reference %s", k)
                    continue
                repo[k] = remote_refs[k]

            if refs:
                # mikhail: explicitly set the head to the last ref.
                repo['HEAD'] = remote_refs[refs[-1]]

            # TODO: mikhail: should we return remote_refs here to be
            # consistent?
        else:
            return remote_refs
Example #10
0
    def get_missing_revs(self, wire, rev1, rev2, path2):
        repo = self._factory.repo(wire)
        LocalGitClient(thin_packs=False).fetch(path2, repo)

        wire_remote = wire.copy()
        wire_remote['path'] = path2
        repo_remote = self._factory.repo(wire_remote)
        LocalGitClient(thin_packs=False).fetch(wire["path"], repo_remote)

        revs = [
            x.commit.id
            for x in repo_remote.get_walker(include=[rev2], exclude=[rev1])
        ]
        return revs
Example #11
0
    def fetch(self, wire, url, apply_refs=True, refs=None):
        if url != 'default' and '://' not in url:
            client = LocalGitClient(url)
        else:
            url_obj = hg_url(url)
            o = self._build_opener(url)
            url, _ = url_obj.authinfo()
            client = HttpGitClient(base_url=url, opener=o)
        repo = self._factory.repo(wire)

        determine_wants = repo.object_store.determine_wants_all
        if refs:
            def determine_wants_requested(references):
                return [references[r] for r in references if r in refs]
            determine_wants = determine_wants_requested

        try:
            remote_refs = client.fetch(
                path=url, target=repo, determine_wants=determine_wants)
        except NotGitRepository:
            log.warning(
                'Trying to fetch from "%s" failed, not a Git repository.', url)
            raise exceptions.AbortException()

        # mikhail: client.fetch() returns all the remote refs, but fetches only
        # refs filtered by `determine_wants` function. We need to filter result
        # as well
        if refs:
            remote_refs = {k: remote_refs[k] for k in remote_refs if k in refs}

        if apply_refs:
            # TODO: johbo: Needs proper test coverage with a git repository
            # that contains a tag object, so that we would end up with
            # a peeled ref at this point.
            PEELED_REF_MARKER = '^{}'
            for k in remote_refs:
                if k.endswith(PEELED_REF_MARKER):
                    log.info("Skipping peeled reference %s", k)
                    continue
                repo[k] = remote_refs[k]

            if refs:
                # mikhail: explicitly set the head to the last ref.
                repo['HEAD'] = remote_refs[refs[-1]]

            # TODO: mikhail: should we return remote_refs here to be
            # consistent?
        else:
            return remote_refs
Example #12
0
    def test_get_refs(self):
        local = open_repo('refs.git')
        self.addCleanup(tear_down_repo, local)

        client = LocalGitClient()
        refs = client.get_refs(local.path)
        self.assertDictEqual(local.refs.as_dict(), refs)
Example #13
0
 def test_fetch_empty(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     out = BytesIO()
     walker = {}
     ret = c.fetch_pack(s.path, lambda heads: [], graph_walker=walker,
         pack_data=out.write)
     self.assertEqual({
         b'HEAD': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
         b'refs/heads/master': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
         b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
         b'refs/tags/mytag-packed': b'b0931cadc54336e78a1d980420e3268903b57a50'
         }, ret)
     self.assertEqual(b"PACK\x00\x00\x00\x02\x00\x00\x00\x00\x02\x9d\x08"
         b"\x82;\xd8\xa8\xea\xb5\x10\xadj\xc7\\\x82<\xfd>\xd3\x1e", out.getvalue())
Example #14
0
 def test_fetch_pack_none(self):
     c = LocalGitClient()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     out = BytesIO()
     walker = MemoryRepo().get_graph_walker()
     ret = c.fetch_pack(
         s.path,
         lambda heads: [b"a90fa2d900a17e99b433217e988c4eb4a2e9a097"],
         graph_walker=walker, pack_data=out.write)
     self.assertEqual({b'HEAD': b'refs/heads/master'}, ret.symrefs)
     self.assertEqual({
         b'HEAD': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
         b'refs/heads/master': b'a90fa2d900a17e99b433217e988c4eb4a2e9a097',
         b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
         b'refs/tags/mytag-packed':
         b'b0931cadc54336e78a1d980420e3268903b57a50'
         }, ret.refs)
     # Hardcoding is not ideal, but we'll fix that some other day..
     self.assertTrue(out.getvalue().startswith(
             b'PACK\x00\x00\x00\x02\x00\x00\x00\x07'))
Example #15
0
def fetch_all(source_repo, target_repo, remote_name=None):
    """Fetch branches and tags from a remote repository

    Unlike :code:`git fetch`, this will also update local branches to point at
    the same commit as their remote counterpart.

     Parameters
    ----------
    source_repo : dulwich.repo.Repo
    target_repo : dulwich.repo.Repo
    remote_name : str
    """
    if remote_name is None:
        remote_name = 'origin'

    refs = LocalGitClient().fetch(source_repo.path, target_repo)

    for key, value in refs.items():
        remote_key = key.replace(
            b'heads', b'remotes/%s' % bytes(remote_name, encoding='UTF-8'))
        target_repo.refs[remote_key] = value
        target_repo[key] = value
Example #16
0
    def send_and_verify(self, branch, local, target):
        """Send branch from local to remote repository and verify it worked."""
        client = LocalGitClient()
        ref_name = b"refs/heads/" + branch
        new_refs = client.send_pack(target.path,
                                    lambda _: {ref_name: local.refs[ref_name]},
                                    local.object_store.generate_pack_contents)

        self.assertEqual(local.refs[ref_name], new_refs[ref_name])

        obj_local = local.get_object(new_refs[ref_name])
        obj_target = target.get_object(new_refs[ref_name])
        self.assertEqual(obj_local, obj_target)
Example #17
0
    def send_and_verify(self, branch, local, target):
        client = LocalGitClient()
        ref_name = b"refs/heads/" + branch
        new_refs = client.send_pack(target.path,
                                    lambda _: {ref_name: local.refs[ref_name]},
                                    local.object_store.generate_pack_contents)

        self.assertEqual(local.refs[ref_name], new_refs[ref_name])

        for name, sha in new_refs.items():
            self.assertEqual(new_refs[name], target.refs[name])

        obj_local = local.get_object(new_refs[ref_name])
        obj_target = target.get_object(new_refs[ref_name])
        self.assertEqual(obj_local, obj_target)
Example #18
0
    def send_and_verify(self, branch, local, target):
        """Send branch from local to remote repository and verify it worked."""
        client = LocalGitClient()
        ref_name = b"refs/heads/" + branch
        result = client.send_pack(target.path,
                                  lambda _: {ref_name: local.refs[ref_name]},
                                  local.generate_pack_data)

        self.assertEqual(local.refs[ref_name], result.refs[ref_name])
        self.assertIs(None, result.agent)
        self.assertEqual({}, result.ref_status)

        obj_local = local.get_object(result.refs[ref_name])
        obj_target = target.get_object(result.refs[ref_name])
        self.assertEqual(obj_local, obj_target)
Example #19
0
 def test_fetch_into_empty(self):
     c = LocalGitClient()
     t = MemoryRepo()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     self.assertEqual(s.get_refs(), c.fetch(s.path, t).refs)
Example #20
0
 def test_fetch_into_empty(self):
     c = LocalGitClient()
     t = MemoryRepo()
     s = open_repo('a.git')
     self.addCleanup(tear_down_repo, s)
     self.assertEqual(s.get_refs(), c.fetch(s.path, t))
Example #21
0
    def test_get_url(self):
        path = "/tmp/repo.git"
        c = LocalGitClient()

        url = c.get_url(path)
        self.assertEqual('file:///tmp/repo.git', url)
Example #22
0
from dulwich.client import LocalGitClient
from dulwich.repo import Repo

home = os.path.expanduser('~')

local_folder = os.path.join(home, 'temp/local'
local = Repo(local_folder)

remote = os.path.join(home, 'temp/remote')

wants = local.object_store.determine_wants_all
remote_refs = LocalGitClient().fetch(remote, local, wants)
local_refs = LocalGitClient().get_refs(local_folder)

print(remote_refs)
print(local_refs)
Example #23
0
 def test_fetch_into_empty(self):
     c = LocalGitClient()
     t = MemoryRepo()
     s = open_repo('a.git')
     self.assertEquals(s.get_refs(), c.fetch(s.path, t))
Example #24
0
    def test_get_url(self):
        path = "/tmp/repo.git"
        c = LocalGitClient()

        url = c.get_url(path)
        self.assertEqual('file:///tmp/repo.git', url)