def setUpClass(cls):
     cls.projdir = tempfile.mkdtemp()  # temporary project directory
     cls.repo = Repo.init(cls.projdir)  # test repo
     obj_store = cls.repo.object_store  # test repo object store
     # commit 1 ('2017-01-19T01:06:43')
     cls.c1 = make_commit(
         id=cls.tag_test_data[cls.test_tags[0]][1],
         commit_time=cls.tag_test_data[cls.test_tags[0]][0],
         message=b'unannotated tag',
         author=cls.committer)
     obj_store.add_object(cls.c1)
     # tag 1: unannotated
     cls.t1 = cls.test_tags[0]
     cls.repo[b'refs/tags/' + cls.t1] = cls.c1.id  # add unannotated tag
     # commit 2 ('2017-01-19T01:11:54')
     cls.c2 = make_commit(
         id=cls.tag_test_data[cls.test_tags[1]][1],
         commit_time=cls.tag_test_data[cls.test_tags[1]][0],
         message=b'annotated tag',
         parents=[cls.c1.id],
         author=cls.committer)
     obj_store.add_object(cls.c2)
     # tag 2: annotated ('2017-01-19T01:13:21')
     cls.t2 = make_tag(cls.c2,
                       id=cls.tag_test_data[cls.test_tags[1]][2][1],
                       name=cls.test_tags[1],
                       tag_time=cls.tag_test_data[cls.test_tags[1]][2][0])
     obj_store.add_object(cls.t2)
     cls.repo[b'refs/heads/master'] = cls.c2.id
     cls.repo[b'refs/tags/' + cls.t2.name] = cls.t2.id  # add annotated tag
Ejemplo n.º 2
0
 def setUpClass(cls):
     cls.projdir = tempfile.mkdtemp()  # temporary project directory
     cls.repo = Repo.init(cls.projdir)  # test repo
     obj_store = cls.repo.object_store  # test repo object store
     # commit 1 ('2017-01-19T01:06:43')
     cls.c1 = make_commit(
         id=cls.tag_test_data[cls.test_tags[0]][1],
         commit_time=cls.tag_test_data[cls.test_tags[0]][0],
         message=b'unannotated tag',
         author=cls.committer
     )
     obj_store.add_object(cls.c1)
     # tag 1: unannotated
     cls.t1 = cls.test_tags[0]
     cls.repo[b'refs/tags/' + cls.t1] = cls.c1.id  # add unannotated tag
     # commit 2 ('2017-01-19T01:11:54')
     cls.c2 = make_commit(
         id=cls.tag_test_data[cls.test_tags[1]][1],
         commit_time=cls.tag_test_data[cls.test_tags[1]][0],
         message=b'annotated tag',
         parents=[cls.c1.id],
         author=cls.committer
     )
     obj_store.add_object(cls.c2)
     # tag 2: annotated ('2017-01-19T01:13:21')
     cls.t2 = make_tag(
         cls.c2,
         id=cls.tag_test_data[cls.test_tags[1]][2][1],
         name=cls.test_tags[1],
         tag_time=cls.tag_test_data[cls.test_tags[1]][2][0]
     )
     obj_store.add_object(cls.t2)
     cls.repo[b'refs/heads/master'] = cls.c2.id
     cls.repo[b'refs/tags/' + cls.t2.name] = cls.t2.id  # add annotated tag
Ejemplo n.º 3
0
    def test_commit_with_change(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        b = Blob.from_string(b"The Bar\n")
        tb = Tree()
        tb.add(b"somename", 0o100644, b.id)
        cb = make_commit(tree=tb.id, parents=[ca.id])
        self.repo.object_store.add_objects([(a, None), (b, None), (ta, None),
                                            (tb, None), (ca, None),
                                            (cb, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
        self.assertMultiLineEqual(
            outstream.getvalue(), """\
--------------------------------------------------
commit: 2c6b6c9cb72c130956657e1fdae58e5b103744fa
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git a/somename b/somename
index ea5c7bf..fd38bcb 100644
--- a/somename
+++ b/somename
@@ -1 +1 @@
-The Foo
+The Bar
""")
Ejemplo n.º 4
0
    def test_commit_with_change(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        b = Blob.from_string(b"The Bar\n")
        tb = Tree()
        tb.add(b"somename", 0o100644, b.id)
        cb = make_commit(tree=tb.id, parents=[ca.id])
        self.repo.object_store.add_objects(
            [(a, None), (b, None), (ta, None), (tb, None),
             (ca, None), (cb, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[cb.id], outstream=outstream)
        self.assertMultiLineEqual(outstream.getvalue(), """\
--------------------------------------------------
commit: 2c6b6c9cb72c130956657e1fdae58e5b103744fa
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git a/somename b/somename
index ea5c7bf..fd38bcb 100644
--- a/somename
+++ b/somename
@@ -1 +1 @@
-The Foo
+The Bar
""")
Ejemplo n.º 5
0
 def test_ff(self):
     r = MemoryRepo()
     base = make_commit()
     c1 = make_commit(parents=[base.id])
     c2 = make_commit(parents=[c1.id])
     r.object_store.add_objects([(base, None), (c1, None), (c2, None)])
     self.assertTrue(can_fast_forward(r, c1.id, c1.id))
     self.assertTrue(can_fast_forward(r, base.id, c1.id))
     self.assertTrue(can_fast_forward(r, c1.id, c2.id))
     self.assertFalse(can_fast_forward(r, c2.id, c1.id))
Ejemplo n.º 6
0
 def test_ff(self):
     store = MemoryObjectStore()
     base = make_commit()
     c1 = make_commit(parents=[base.id])
     c2 = make_commit(parents=[c1.id])
     store.add_objects([(base, None), (c1, None), (c2, None)])
     self.assertTrue(can_fast_forward(store, c1.id, c1.id))
     self.assertTrue(can_fast_forward(store, base.id, c1.id))
     self.assertTrue(can_fast_forward(store, c1.id, c2.id))
     self.assertFalse(can_fast_forward(store, c2.id, c1.id))
Ejemplo n.º 7
0
 def test_diverged(self):
     store = MemoryObjectStore()
     base = make_commit()
     c1 = make_commit(parents=[base.id])
     c2a = make_commit(parents=[c1.id], message=b'2a')
     c2b = make_commit(parents=[c1.id], message=b'2b')
     store.add_objects([(base, None), (c1, None), (c2a, None), (c2b, None)])
     self.assertTrue(can_fast_forward(store, c1.id, c2a.id))
     self.assertTrue(can_fast_forward(store, c1.id, c2b.id))
     self.assertFalse(can_fast_forward(store, c2a.id, c2b.id))
     self.assertFalse(can_fast_forward(store, c2b.id, c2a.id))
Ejemplo n.º 8
0
 def test_diverged(self):
     r = MemoryRepo()
     base = make_commit()
     c1 = make_commit(parents=[base.id])
     c2a = make_commit(parents=[c1.id], message=b"2a")
     c2b = make_commit(parents=[c1.id], message=b"2b")
     r.object_store.add_objects([(base, None), (c1, None), (c2a, None),
                                 (c2b, None)])
     self.assertTrue(can_fast_forward(r, c1.id, c2a.id))
     self.assertTrue(can_fast_forward(r, c1.id, c2b.id))
     self.assertFalse(can_fast_forward(r, c2a.id, c2b.id))
     self.assertFalse(can_fast_forward(r, c2b.id, c2a.id))
Ejemplo n.º 9
0
    def test_commit_serialize(self):
        attrs = {
            'tree':
            b'd80c186a03f423a81b39df39dc87fd269736ca86',
            'parents': [
                b'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
                b'4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'
            ],
            'author':
            b'James Westby <*****@*****.**>',
            'committer':
            b'James Westby <*****@*****.**>',
            'commit_time':
            1174773719,
            'author_time':
            1174773719,
            'commit_timezone':
            0,
            'author_timezone':
            0,
            'message':
            b'Merge ../b\n'
        }
        commit = make_commit(**attrs)

        with self.assert_serialization_on_change(commit):
            commit.parents = [b'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd']
Ejemplo n.º 10
0
    def test_get_tagged(self):
        refs = {
            b"refs/tags/tag1": ONE,
            b"refs/tags/tag2": TWO,
            b"refs/heads/master": FOUR,  # not a tag, no peeled value
        }
        # repo needs to peel this object
        self._repo.object_store.add_object(make_commit(id=FOUR))
        self._repo.refs._update(refs)
        peeled = {
            b"refs/tags/tag1": b"1234" * 10,
            b"refs/tags/tag2": b"5678" * 10,
        }
        self._repo.refs._update_peeled(peeled)

        caps = list(self._handler.required_capabilities()) + [b"include-tag"]
        self._handler.set_client_capabilities(caps)
        self.assertEqual(
            {
                b"1234" * 10: ONE,
                b"5678" * 10: TWO
            },
            self._handler.get_tagged(refs, repo=self._repo),
        )

        # non-include-tag case
        caps = self._handler.required_capabilities()
        self._handler.set_client_capabilities(caps)
        self.assertEqual({}, self._handler.get_tagged(refs, repo=self._repo))
Ejemplo n.º 11
0
    def test_get_tagged(self):
        refs = {
            'refs/tags/tag1': ONE,
            'refs/tags/tag2': TWO,
            'refs/heads/master': FOUR,  # not a tag, no peeled value
        }
        # repo needs to peel this object
        self._repo.object_store.add_object(make_commit(id=FOUR))
        self._repo.refs._update(refs)
        peeled = {
            'refs/tags/tag1': '1234' * 10,
            'refs/tags/tag2': '5678' * 10,
        }
        self._repo.refs._update_peeled(peeled)

        caps = list(self._handler.required_capabilities()) + ['include-tag']
        self._handler.set_client_capabilities(caps)
        self.assertEqual({
            '1234' * 10: ONE,
            '5678' * 10: TWO
        }, self._handler.get_tagged(refs, repo=self._repo))

        # non-include-tag case
        caps = self._handler.required_capabilities()
        self._handler.set_client_capabilities(caps)
        self.assertEqual({}, self._handler.get_tagged(refs, repo=self._repo))
Ejemplo n.º 12
0
 def make_commit(self, **kwargs):
     attrs = {
         'tree':
         b'd80c186a03f423a81b39df39dc87fd269736ca86',
         'parents': [
             b'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
             b'4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'
         ],
         'author':
         b'James Westby <*****@*****.**>',
         'committer':
         b'James Westby <*****@*****.**>',
         'commit_time':
         1174773719,
         'author_time':
         1174773719,
         'commit_timezone':
         0,
         'author_timezone':
         0,
         'message':
         b'Merge ../b\n'
     }
     attrs.update(kwargs)
     return make_commit(**attrs)
Ejemplo n.º 13
0
    def test_commit_no_parent(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
        self.assertMultiLineEqual(
            outstream.getvalue(), """\
--------------------------------------------------
commit: 344da06c1bb85901270b3e8875c988a027ec087d
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git /dev/null b/somename
new mode 100644
index 0000000..ea5c7bf 100644
--- /dev/null
+++ b/somename
@@ -0,0 +1 @@
+The Foo
""")
Ejemplo n.º 14
0
    def test_commit_no_parent(self):
        a = Blob.from_string(b"The Foo\n")
        ta = Tree()
        ta.add(b"somename", 0o100644, a.id)
        ca = make_commit(tree=ta.id)
        self.repo.object_store.add_objects([(a, None), (ta, None), (ca, None)])
        outstream = StringIO()
        porcelain.show(self.repo.path, objects=[ca.id], outstream=outstream)
        self.assertMultiLineEqual(outstream.getvalue(), """\
--------------------------------------------------
commit: 344da06c1bb85901270b3e8875c988a027ec087d
Author: Test Author <*****@*****.**>
Committer: Test Committer <*****@*****.**>
Date:   Fri Jan 01 2010 00:00:00 +0000

Test message.

diff --git /dev/null b/somename
new mode 100644
index 0000000..ea5c7bf 100644
--- /dev/null
+++ b/somename
@@ -0,0 +1 @@
+The Foo
""")
Ejemplo n.º 15
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({'/': self._repo})
     self._walker = ProtocolGraphWalker(
         TestUploadPackHandler(backend, ['/', 'host=lolcats'], TestProto()),
         self._repo.object_store, self._repo.get_peeled)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
 def test_receive_pack(self):
     commit = make_commit(id=ONE, parents=[], commit_time=111)
     self.backend.repos["/"] = MemoryRepo.init_bare([commit], {"refs/heads/master": commit.id})
     outf = BytesIO()
     exitcode = self.serve_command(ReceivePackHandler, ["/"], BytesIO("0000"), outf)
     outlines = outf.getvalue().splitlines()
     self.assertEqual(2, len(outlines))
     self.assertEqual("1111111111111111111111111111111111111111 refs/heads/master", outlines[0][4:].split("\x00")[0])
     self.assertEqual("0000", outlines[-1])
     self.assertEqual(0, exitcode)
Ejemplo n.º 18
0
 def test_nothing_to_do_no_wants(self):
     # Don't send a pack if the client didn't ask for anything.
     refs = {b'refs/tags/tag1': ONE}
     tree = Tree()
     self._repo.object_store.add_object(tree)
     self._repo.object_store.add_object(make_commit(id=ONE, tree=tree))
     self._repo.refs._update(refs)
     self._handler.proto.set_output([None])
     self._handler.handle()
     # The server should not send a pack, since the client didn't ask for
     # anything.
     self.assertEqual([], self._handler.proto._received[1])
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def test_commit_copy(self):
     attrs = {'tree': 'd80c186a03f423a81b39df39dc87fd269736ca86',
              'parents': ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
                          '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'],
              'author': 'James Westby <*****@*****.**>',
              'committer': 'James Westby <*****@*****.**>',
              'commit_time': 1174773719,
              'author_time': 1174773719,
              'commit_timezone': 0,
              'author_timezone': 0,
              'message':  'Merge ../b\n'}
     commit = make_commit(**attrs)
     self.assert_copy(commit)
Ejemplo n.º 21
0
 def make_commit(self, **kwargs):
     attrs = {'tree': b'd80c186a03f423a81b39df39dc87fd269736ca86',
              'parents': [b'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
                          b'4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'],
              'author': b'James Westby <*****@*****.**>',
              'committer': b'James Westby <*****@*****.**>',
              'commit_time': 1174773719,
              'author_time': 1174773719,
              'commit_timezone': 0,
              'author_timezone': 0,
              'message':  b'Merge ../b\n'}
     attrs.update(kwargs)
     return make_commit(**attrs)
Ejemplo n.º 22
0
    def test_get_tagged(self):
        refs = {"refs/tags/tag1": ONE, "refs/tags/tag2": TWO, "refs/heads/master": FOUR}  # not a tag, no peeled value
        # repo needs to peel this object
        self._repo.object_store.add_object(make_commit(id=FOUR))
        self._repo.refs._update(refs)
        peeled = {"refs/tags/tag1": "1234" * 10, "refs/tags/tag2": "5678" * 10}
        self._repo.refs._update_peeled(peeled)

        caps = list(self._handler.required_capabilities()) + ["include-tag"]
        self._handler.set_client_capabilities(caps)
        self.assertEqual({"1234" * 10: ONE, "5678" * 10: TWO}, self._handler.get_tagged(refs, repo=self._repo))

        # non-include-tag case
        caps = self._handler.required_capabilities()
        self._handler.set_client_capabilities(caps)
        self.assertEqual({}, self._handler.get_tagged(refs, repo=self._repo))
Ejemplo n.º 23
0
 def test_nothing_to_do_but_wants(self):
     # Just the fact that the client claims to want an object is enough
     # for sending a pack. Even if there turns out to be nothing.
     refs = {b'refs/tags/tag1': ONE}
     tree = Tree()
     self._repo.object_store.add_object(tree)
     self._repo.object_store.add_object(make_commit(id=ONE, tree=tree))
     self._repo.refs._update(refs)
     self._handler.proto.set_output([
         b'want ' + ONE + b' side-band-64k thin-pack ofs-delta', None,
         b'have ' + ONE, b'done', None
     ])
     self._handler.handle()
     # The server should always send a pack, even if it's empty.
     self.assertTrue(
         self._handler.proto.get_received_line(1).startswith(b'PACK'))
Ejemplo n.º 24
0
    def test_get_tagged(self):
        refs = {
            b'refs/tags/tag1': ONE,
            b'refs/tags/tag2': TWO,
            b'refs/heads/master': FOUR,  # not a tag, no peeled value
            }
        # repo needs to peel this object
        self._repo.object_store.add_object(make_commit(id=FOUR))
        self._repo.refs._update(refs)
        peeled = {
            b'refs/tags/tag1': b'1234' * 10,
            b'refs/tags/tag2': b'5678' * 10,
            }
        self._repo.refs._update_peeled(peeled)

        caps = list(self._handler.required_capabilities()) + [b'include-tag']
        self._handler.set_client_capabilities(caps)
        self.assertEqual({b'1234' * 10: ONE, b'5678' * 10: TWO},
                          self._handler.get_tagged(refs, repo=self._repo))

        # non-include-tag case
        caps = self._handler.required_capabilities()
        self._handler.set_client_capabilities(caps)
        self.assertEqual({}, self._handler.get_tagged(refs, repo=self._repo))
Ejemplo n.º 25
0
 def make_commit(self, **attrs):
     commit = make_commit(**attrs)
     self._store.add_object(commit)
     return commit
Ejemplo n.º 26
0
 def test_stub_sha(self):
     sha = b'5' * 40
     c = make_commit(id=sha, message=b'foo')
     self.assertTrue(isinstance(c, Commit))
     self.assertEqual(sha, c.id)
     self.assertNotEqual(sha, c._make_sha())
Ejemplo n.º 27
0
 def make_commit(self, **attrs):
     commit = make_commit(**attrs)
     self._store.add_object(commit)
     return commit
Ejemplo n.º 28
0
 def test_stub_sha(self):
     sha = '5' * 40
     c = make_commit(id=sha, message='foo')
     self.assertTrue(isinstance(c, Commit))
     self.assertEqual(sha, c.id)
     self.assertNotEqual(sha, c._make_sha())