def setUp(self):
     super(GitImportProcessorTests, self).setUp()
     self.repo = MemoryRepo()
     try:
         from my_dulwich.fastexport import GitImportProcessor
     except ImportError:
         raise SkipTest("python-fastimport not available")
     self.processor = GitImportProcessor(self.repo)
示例#2
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'))
示例#3
0
 def setUp(self):
     super(ProtocolGraphWalkerEmptyTestCase, self).setUp()
     self._repo = MemoryRepo.init_bare([], {})
     backend = DictBackend({b'/': self._repo})
     self._walker = _ProtocolGraphWalker(
         TestUploadPackHandler(backend, [b'/', b'host=lolcats'],
                               TestProto()), self._repo.object_store,
         self._repo.get_peeled, self._repo.refs.get_symrefs)
示例#4
0
def _test_backend(objects, refs=None, named_files=None):
    if not refs:
        refs = {}
    if not named_files:
        named_files = {}
    repo = MemoryRepo.init_bare(objects, refs)
    for path, contents in named_files.items():
        repo._put_named_file(path, contents)
    return DictBackend({'/': repo})
    def test_commit_config_identity_in_memoryrepo(self):
        # commit falls back to the users' identity if it wasn't specified
        r = MemoryRepo.init_bare([], {})
        c = r.get_config()
        c.set((b"user", ), b"name", b"Jelmer")
        c.set((b"user", ), b"email", b"*****@*****.**")

        commit_sha = r.do_commit(b'message', tree=objects.Tree().id)
        self.assertEqual(b"Jelmer <*****@*****.**>", r[commit_sha].author)
        self.assertEqual(b"Jelmer <*****@*****.**>",
                         r[commit_sha].committer)
示例#6
0
 def test_receive_pack(self):
     commit = make_commit(id=ONE, parents=[], commit_time=111)
     self.backend.repos[b"/"] = MemoryRepo.init_bare(
         [commit], {b"refs/heads/master": commit.id})
     outf = BytesIO()
     exitcode = self.serve_command(ReceivePackHandler, [b"/"],
                                   BytesIO(b"0000"), outf)
     outlines = outf.getvalue().splitlines()
     self.assertEqual(2, len(outlines))
     self.assertEqual(
         b"1111111111111111111111111111111111111111 refs/heads/master",
         outlines[0][4:].split(b"\x00")[0])
     self.assertEqual(b"0000", outlines[-1])
     self.assertEqual(0, exitcode)
示例#7
0
 def setUp(self):
     super(ProtocolGraphWalkerTestCase, self).setUp()
     # Create the following commit tree:
     #   3---5
     #  /
     # 1---2---4
     commits = [
         make_commit(id=ONE, parents=[], commit_time=111),
         make_commit(id=TWO, parents=[ONE], commit_time=222),
         make_commit(id=THREE, parents=[ONE], commit_time=333),
         make_commit(id=FOUR, parents=[TWO], commit_time=444),
         make_commit(id=FIVE, parents=[THREE], commit_time=555),
     ]
     self._repo = MemoryRepo.init_bare(commits, {})
     backend = DictBackend({b'/': self._repo})
     self._walker = _ProtocolGraphWalker(
         TestUploadPackHandler(backend, [b'/', b'host=lolcats'],
                               TestProto()), self._repo.object_store,
         self._repo.get_peeled, self._repo.refs.get_symrefs)
    def setUp(self):
        super(GraftsInMemoryRepoTests, self).setUp()
        r = self._repo = MemoryRepo()

        self._shas = []

        tree = Tree()

        commit_kwargs = {
            'committer': b'Test Committer <*****@*****.**>',
            'author': b'Test Author <*****@*****.**>',
            'commit_timestamp': 12395,
            'commit_timezone': 0,
            'author_timestamp': 12395,
            'author_timezone': 0,
            'tree': tree.id
        }

        self._shas.append(r.do_commit(b'empty commit', **commit_kwargs))
        self._shas.append(r.do_commit(b'empty commit', **commit_kwargs))
        self._shas.append(r.do_commit(b'empty commit', **commit_kwargs))
 def test_nonexistent(self):
     r = MemoryRepo()
     self.assertRaises(KeyError, parse_object, r, "thisdoesnotexist")
示例#10
0
 def setUp(self):
     super(ReceivePackHandlerTestCase, self).setUp()
     self._repo = MemoryRepo.init_bare([], {})
     backend = DictBackend({b'/': self._repo})
     self._handler = ReceivePackHandler(backend, [b'/', b'host=lolcathost'],
                                        TestProto())
示例#11
0
    def test_bad_repo_path(self):
        repo = MemoryRepo.init_bare([], {})
        backend = DictBackend({b'/': repo})

        self.assertRaises(NotGitRepository,
                          lambda: backend.open_repository('/ups'))
示例#12
0
 def test_nonexistant(self):
     repo = MemoryRepo.init_bare([], {})
     backend = DictBackend({b'/': repo})
     self.assertRaises(NotGitRepository, backend.open_repository,
                       "/does/not/exist/unless/foo")
 def test_commit_by_sha(self):
     r = MemoryRepo()
     c1, c2, c3 = build_commit_graph(r.object_store,
                                     [[1], [2, 1], [3, 1, 2]])
     self.assertEqual([c1], list(parse_commit_range(r, c1.id)))
 def test_nonexistent(self):
     r = MemoryRepo()
     self.assertRaises(KeyError, parse_commit_range, r, "thisdoesnotexist")
class GitImportProcessorTests(TestCase):
    """Tests for the GitImportProcessor tests."""
    def setUp(self):
        super(GitImportProcessorTests, self).setUp()
        self.repo = MemoryRepo()
        try:
            from my_dulwich.fastexport import GitImportProcessor
        except ImportError:
            raise SkipTest("python-fastimport not available")
        self.processor = GitImportProcessor(self.repo)

    def test_reset_handler(self):
        from fastimport import commands
        [c1] = build_commit_graph(self.repo.object_store, [[1]])
        cmd = commands.ResetCommand(b"refs/heads/foo", c1.id)
        self.processor.reset_handler(cmd)
        self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])
        self.assertEqual(c1.id, self.processor.last_commit)

    def test_reset_handler_marker(self):
        from fastimport import commands
        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
        self.processor.markers[b'10'] = c1.id
        cmd = commands.ResetCommand(b"refs/heads/foo", b':10')
        self.processor.reset_handler(cmd)
        self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])

    def test_reset_handler_default(self):
        from fastimport import commands
        [c1, c2] = build_commit_graph(self.repo.object_store, [[1], [2]])
        cmd = commands.ResetCommand(b"refs/heads/foo", None)
        self.processor.reset_handler(cmd)
        self.assertEqual(ZERO_SHA, self.repo.get_refs()[b"refs/heads/foo"])

    def test_commit_handler(self):
        from fastimport import commands
        cmd = commands.CommitCommand(
            b"refs/heads/foo", b"mrkr",
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None,
            [], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(b"Jelmer <*****@*****.**>", commit.author)
        self.assertEqual(b"Jelmer <*****@*****.**>", commit.committer)
        self.assertEqual(b"FOO", commit.message)
        self.assertEqual([], commit.parents)
        self.assertEqual(432432432.0, commit.commit_time)
        self.assertEqual(432432432.0, commit.author_time)
        self.assertEqual(3600, commit.commit_timezone)
        self.assertEqual(3600, commit.author_timezone)
        self.assertEqual(commit, self.repo[b"refs/heads/foo"])

    def test_commit_handler_markers(self):
        from fastimport import commands
        [c1, c2, c3] = build_commit_graph(self.repo.object_store,
                                          [[1], [2], [3]])
        self.processor.markers[b'10'] = c1.id
        self.processor.markers[b'42'] = c2.id
        self.processor.markers[b'98'] = c3.id
        cmd = commands.CommitCommand(
            b"refs/heads/foo", b"mrkr",
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO",
            b':10', [b':42', b':98'], [])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(c1.id, commit.parents[0])
        self.assertEqual(c2.id, commit.parents[1])
        self.assertEqual(c3.id, commit.parents[2])

    def test_import_stream(self):
        markers = self.processor.import_stream(
            BytesIO(b"""blob
mark :1
data 11
text for a

commit refs/heads/master
mark :2
committer Joe Foo <*****@*****.**> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a

"""))
        self.assertEqual(2, len(markers))
        self.assertTrue(isinstance(self.repo[markers[b"1"]], Blob))
        self.assertTrue(isinstance(self.repo[markers[b"2"]], Commit))

    def test_file_add(self):
        from fastimport import commands
        cmd = commands.BlobCommand(b"23", b"data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
            b"refs/heads/foo", b"mrkr",
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None,
            [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        self.assertEqual(
            [(b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172')],
            self.repo[commit.tree].items())

    def simple_commit(self):
        from fastimport import commands
        cmd = commands.BlobCommand(b"23", b"data")
        self.processor.blob_handler(cmd)
        cmd = commands.CommitCommand(
            b"refs/heads/foo", b"mrkr",
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None,
            [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
        self.processor.commit_handler(cmd)
        commit = self.repo[self.processor.last_commit]
        return commit

    def make_file_commit(self, file_cmds):
        """Create a trivial commit with the specified file commands.

        :param file_cmds: File commands to run.
        :return: The created commit object
        """
        from fastimport import commands
        cmd = commands.CommitCommand(
            b"refs/heads/foo", b"mrkr",
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600),
            (b"Jelmer", b"*****@*****.**", 432432432.0, 3600), b"FOO", None,
            [], file_cmds)
        self.processor.commit_handler(cmd)
        return self.repo[self.processor.last_commit]

    def test_file_copy(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
            [commands.FileCopyCommand(b"path", b"new_path")])
        self.assertEqual([
            (b'new_path', 0o100644,
             b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
            (b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
        ], self.repo[commit.tree].items())

    def test_file_move(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit(
            [commands.FileRenameCommand(b"path", b"new_path")])
        self.assertEqual([
            (b'new_path', 0o100644,
             b'6320cd248dd8aeaab759d5871f8781b5c0505172'),
        ], self.repo[commit.tree].items())

    def test_file_delete(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteCommand(b"path")])
        self.assertEqual([], self.repo[commit.tree].items())

    def test_file_deleteall(self):
        from fastimport import commands
        self.simple_commit()
        commit = self.make_file_commit([commands.FileDeleteAllCommand()])
        self.assertEqual([], self.repo[commit.tree].items())
 def test_from_commit(self):
     r = MemoryRepo()
     c1, c2, c3 = build_commit_graph(r.object_store,
                                     [[1], [2, 1], [3, 1, 2]])
     self.assertEqual(r[c1.tree], parse_tree(r, c1.id))
     self.assertEqual(r[c1.tree], parse_tree(r, c1.tree))
 def test_create_memory(self):
     repo = MemoryRepo.init_bare([], {})
     self._check_repo_contents(repo, True)
 def test_set_description(self):
     r = MemoryRepo.init_bare([], {})
     description = b"Some description"
     r.set_description(description)
     self.assertEqual(description, r.get_description())
 def test_blob_by_sha(self):
     r = MemoryRepo()
     b = Blob.from_string(b"Blah")
     r.object_store.add_object(b)
     self.assertEqual(b, parse_object(r, b.id))
示例#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).refs)