def test_add(self):
     myhexsha = b'd80c186a03f423a81b39df39dc87fd269736ca86'
     x = Tree()
     x.add(b'myname', 0o100755, myhexsha)
     self.assertEqual(x[b'myname'], (0o100755, myhexsha))
     self.assertEqual(b'100755 myname\0' + hex_to_sha(myhexsha),
                      x.as_raw_string())
    def test_emit_commit(self):
        b = Blob()
        b.data = b"FOO"
        t = Tree()
        t.add(b"foo", stat.S_IFREG | 0o644, b.id)
        c = Commit()
        c.committer = c.author = b"Jelmer <jelmer@host>"
        c.author_time = c.commit_time = 1271345553
        c.author_timezone = c.commit_timezone = 0
        c.message = b"msg"
        c.tree = t.id
        self.store.add_objects([(b, None), (t, None), (c, None)])
        self.fastexporter.emit_commit(c, b"refs/heads/master")
        self.assertEqual(
            b"""blob
mark :1
data 3
FOO
commit refs/heads/master
mark :2
author Jelmer <jelmer@host> 1271345553 +0000
committer Jelmer <jelmer@host> 1271345553 +0000
data 3
msg
M 644 :1 foo
""", self.stream.getvalue())
 def test_full_tree(self):
     c = self.make_commit(commit_time=30)
     t = Tree()
     t.add(b'data-x', 0o644, Blob().id)
     c.tree = t
     c1 = Commit()
     c1.set_raw_string(c.as_raw_string())
     self.assertEqual(t.id, c1.tree)
     self.assertEqual(c.as_raw_string(), c1.as_raw_string())
 def _get_example_tar_stream(self, *tar_stream_args, **tar_stream_kwargs):
     store = MemoryObjectStore()
     b1 = Blob.from_string(b"somedata")
     store.add_object(b1)
     t1 = Tree()
     t1.add(b"somename", 0o100644, b1.id)
     store.add_object(t1)
     stream = b''.join(
         tar_stream(store, t1, *tar_stream_args, **tar_stream_kwargs))
     return BytesIO(stream)
 def test_add_old_order(self):
     myhexsha = b'd80c186a03f423a81b39df39dc87fd269736ca86'
     x = Tree()
     warnings.simplefilter("ignore", DeprecationWarning)
     try:
         x.add(0o100755, b'myname', myhexsha)
     finally:
         warnings.resetwarnings()
     self.assertEqual(x[b'myname'], (0o100755, myhexsha))
     self.assertEqual(b'100755 myname\0' + hex_to_sha(myhexsha),
                      x.as_raw_string())
Exemple #6
0
 def build_tree(path):
     tree = Tree()
     for basename, entry in trees[path].items():
         if isinstance(entry, dict):
             mode = stat.S_IFDIR
             sha = build_tree(pathjoin(path, basename))
         else:
             (mode, sha) = entry
         tree.add(basename, mode, sha)
     object_store.add_object(tree)
     return tree.id
Exemple #7
0
def create_commit(marker=None):
    blob = Blob.from_string(b'The blob content ' + marker)
    tree = Tree()
    tree.add(b"thefile " + marker, 0o100644, blob.id)
    cmt = Commit()
    cmt.tree = tree.id
    cmt.author = cmt.committer = b"John Doe <*****@*****.**>"
    cmt.message = marker
    tz = parse_timezone(b'-0200')[0]
    cmt.commit_time = cmt.author_time = int(time.time())
    cmt.commit_timezone = cmt.author_timezone = tz
    return cmt, tree, blob
    def test_tree_copy_after_update(self):
        """Check Tree.id is correctly updated when the tree is copied after updated.
        """
        shas = []
        tree = Tree()
        shas.append(tree.id)
        tree.add(b'data', 0o644, Blob().id)
        copied = tree.copy()
        shas.append(tree.id)
        shas.append(copied.id)

        self.assertNotIn(shas[0], shas[1:])
        self.assertEqual(shas[1], shas[2])
Exemple #9
0
 def test_tree_diff_submodule(self):
     f = BytesIO()
     store = MemoryObjectStore()
     tree1 = Tree()
     tree1.add(b"asubmodule", S_IFGITLINK,
               b"06d0bdd9e2e20377b3180e4986b14c8549b393e4")
     tree2 = Tree()
     tree2.add(b"asubmodule", S_IFGITLINK,
               b"cc975646af69f279396d4d5e1379ac6af80ee637")
     store.add_objects([(o, None) for o in [tree1, tree2]])
     write_tree_diff(f, store, tree1.id, tree2.id)
     self.assertEqual([
         b'diff --git a/asubmodule b/asubmodule',
         b'index 06d0bdd..cc97564 160000',
         b'--- a/asubmodule',
         b'+++ b/asubmodule',
         b'@@ -1 +1 @@',
         b'-Submodule commit 06d0bdd9e2e20377b3180e4986b14c8549b393e4',
         b'+Submodule commit cc975646af69f279396d4d5e1379ac6af80ee637',
     ],
                      f.getvalue().splitlines())
Exemple #10
0
 def test_tree_diff(self):
     f = BytesIO()
     store = MemoryObjectStore()
     added = Blob.from_string(b"add\n")
     removed = Blob.from_string(b"removed\n")
     changed1 = Blob.from_string(b"unchanged\nremoved\n")
     changed2 = Blob.from_string(b"unchanged\nadded\n")
     unchanged = Blob.from_string(b"unchanged\n")
     tree1 = Tree()
     tree1.add(b"removed.txt", 0o644, removed.id)
     tree1.add(b"changed.txt", 0o644, changed1.id)
     tree1.add(b"unchanged.txt", 0o644, changed1.id)
     tree2 = Tree()
     tree2.add(b"added.txt", 0o644, added.id)
     tree2.add(b"changed.txt", 0o644, changed2.id)
     tree2.add(b"unchanged.txt", 0o644, changed1.id)
     store.add_objects([
         (o, None) for o in
         [tree1, tree2, added, removed, changed1, changed2, unchanged]
     ])
     write_tree_diff(f, store, tree1.id, tree2.id)
     self.assertEqual([
         b'diff --git /dev/null b/added.txt',
         b'new mode 644',
         b'index 0000000..76d4bb8 644',
         b'--- /dev/null',
         b'+++ b/added.txt',
         b'@@ -0,0 +1 @@',
         b'+add',
         b'diff --git a/changed.txt b/changed.txt',
         b'index bf84e48..1be2436 644',
         b'--- a/changed.txt',
         b'+++ b/changed.txt',
         b'@@ -1,2 +1,2 @@',
         b' unchanged',
         b'-removed',
         b'+added',
         b'diff --git a/removed.txt /dev/null',
         b'deleted mode 644',
         b'index 2c3f0b3..0000000',
         b'--- a/removed.txt',
         b'+++ /dev/null',
         b'@@ -1 +0,0 @@',
         b'-removed',
     ],
                      f.getvalue().splitlines())