def test_attrs(self):
     c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
                                 attrs={1: {
                                     'message': b'Hooray!'
                                 }})
     self.assertEqual(b'Hooray!', c1.message)
     self.assertEqual(b'Commit 2', c2.message)
    def setUp(self):
        super(MOFLinearRepoTest, self).setUp()
        # present in 1, removed in 3
        f1_1 = make_object(Blob, data=b'f1')
        # present in all revisions, changed in 2 and 3
        f2_1 = make_object(Blob, data=b'f2')
        f2_2 = make_object(Blob, data=b'f2-changed')
        f2_3 = make_object(Blob, data=b'f2-changed-again')
        # added in 2, left unmodified in 3
        f3_2 = make_object(Blob, data=b'f3')

        commit_spec = [[1], [2, 1], [3, 2]]
        trees = {
            1: [(b'f1', f1_1), (b'f2', f2_1)],
            2: [(b'f1', f1_1), (b'f2', f2_2), (b'f3', f3_2)],
            3: [(b'f2', f2_3), (b'f3', f3_2)]
        }
        # commit 1: f1 and f2
        # commit 2: f3 added, f2 changed. Missing shall report commit id and a
        # tree referenced by commit
        # commit 3: f1 removed, f2 changed. Commit sha and root tree sha shall
        # be reported as modified
        self.commits = build_commit_graph(self.store, commit_spec, trees)
        self.missing_1_2 = [self.cmt(2).id, self.cmt(2).tree, f2_2.id, f3_2.id]
        self.missing_2_3 = [self.cmt(3).id, self.cmt(3).tree, f2_3.id]
        self.missing_1_3 = [
            self.cmt(2).id,
            self.cmt(3).id,
            self.cmt(2).tree,
            self.cmt(3).tree, f2_2.id, f3_2.id, f2_3.id
        ]
    def setUp(self):
        super(MOFMergeForkRepoTest, self).setUp()
        f1_1 = make_object(Blob, data=b'f1')
        f1_2 = make_object(Blob, data=b'f1-2')
        f1_4 = make_object(Blob, data=b'f1-4')
        f1_7 = make_object(Blob, data=b'f1-2')  # same data as in rev 2
        f2_1 = make_object(Blob, data=b'f2')
        f2_3 = make_object(Blob, data=b'f2-3')
        f3_3 = make_object(Blob, data=b'f3')
        f3_5 = make_object(Blob, data=b'f3-5')
        commit_spec = [[1], [2, 1], [3, 2], [4, 2], [5, 3], [6, 3, 4], [7, 6]]
        trees = {
            1: [(b'f1', f1_1), (b'f2', f2_1)],
            2: [(b'f1', f1_2), (b'f2', f2_1)],  # f1 changed
            # f3 added, f2 changed
            3: [(b'f1', f1_2), (b'f2', f2_3), (b'f3', f3_3)],
            4: [(b'f1', f1_4), (b'f2', f2_1)],  # f1 changed
            5: [(b'f1', f1_2), (b'f3', f3_5)],  # f2 removed, f3 changed
            # merged 3 and 4
            6: [(b'f1', f1_4), (b'f2', f2_3), (b'f3', f3_3)],
            # f1 changed to match rev2. f3 removed
            7: [(b'f1', f1_7), (b'f2', f2_3)]
        }
        self.commits = build_commit_graph(self.store, commit_spec, trees)

        self.f1_2_id = f1_2.id
        self.f1_4_id = f1_4.id
        self.f1_7_id = f1_7.id
        self.f2_3_id = f2_3.id
        self.f3_3_id = f3_3.id

        self.assertEqual(f1_2.id, f1_7.id, "[sanity]")
 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_empty(self):
     store = MemoryObjectStore()
     c1, c2, c3 = build_commit_graph(store, [[1], [2, 1], [3, 1, 2]])
     tree = store[c3.tree]
     stream = b''.join(tar_stream(store, tree, 10))
     out = BytesIO(stream)
     tf = tarfile.TarFile(fileobj=out)
     self.addCleanup(tf.close)
     self.assertEqual([], tf.getnames())
Exemplo n.º 7
0
 def make_commits(self, commit_spec, **kwargs):
     times = kwargs.pop('times', [])
     attrs = kwargs.pop('attrs', {})
     for i, t in enumerate(times):
         attrs.setdefault(i + 1, {})['commit_time'] = t
     return build_commit_graph(self.store,
                               commit_spec,
                               attrs=attrs,
                               **kwargs)
 def test_linear(self):
     c1, c2 = build_commit_graph(self.store, [[1], [2, 1]])
     for obj_id in [c1.id, c2.id, c1.tree, c2.tree]:
         self.assertTrue(obj_id in self.store)
     self.assertEqual([], c1.parents)
     self.assertEqual([c1.id], c2.parents)
     self.assertEqual(c1.tree, c2.tree)
     self.assertEqual([], self.store[c1.tree].items())
     self.assertTrue(c2.commit_time > c1.commit_time)
 def test_trees(self):
     a1 = make_object(Blob, data=b'aaa1')
     a2 = make_object(Blob, data=b'aaa2')
     c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
                                 trees={
                                     1: [(b'a', a1)],
                                     2: [(b'a', a2, 0o100644)]
                                 })
     self.assertEqual((0o100644, a1.id), self.store[c1.tree][b'a'])
     self.assertEqual((0o100644, a2.id), self.store[c2.tree][b'a'])
 def test_commit_time(self):
     c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]],
                                     attrs={
                                         1: {
                                             'commit_time': 124
                                         },
                                         2: {
                                             'commit_time': 123
                                         }
                                     })
     self.assertEqual(124, c1.commit_time)
     self.assertEqual(123, c2.commit_time)
     self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)
 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 setUp(self):
        super(MOFTagsTest, self).setUp()
        f1_1 = make_object(Blob, data=b'f1')
        commit_spec = [[1]]
        trees = {1: [(b'f1', f1_1)]}
        self.commits = build_commit_graph(self.store, commit_spec, trees)

        self._normal_tag = make_tag(self.cmt(1))
        self.store.add_object(self._normal_tag)

        self._tag_of_tag = make_tag(self._normal_tag)
        self.store.add_object(self._tag_of_tag)

        self._tag_of_tree = make_tag(self.store[self.cmt(1).tree])
        self.store.add_object(self._tag_of_tree)

        self._tag_of_blob = make_tag(f1_1)
        self.store.add_object(self._tag_of_blob)

        self._tag_of_tag_of_blob = make_tag(self._tag_of_blob)
        self.store.add_object(self._tag_of_tag_of_blob)

        self.f1_1_id = f1_1.id
 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_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_merge(self):
     c1, c2, c3, c4 = build_commit_graph(self.store,
                                         [[1], [2, 1], [3, 1], [4, 2, 3]])
     self.assertEqual([c2.id, c3.id], c4.parents)
     self.assertTrue(c4.commit_time > c2.commit_time)
     self.assertTrue(c4.commit_time > c3.commit_time)
 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"])