Ejemplo n.º 1
0
    def test_tree_commit(self):
        g = Git(GitOpt(), cwd=superp)

        # get the content of parent of master
        # Thus the changes looks like reverting the changes in master.
        tree = g.tree_of('master~')
        dd("tree:", tree)

        commit = g.tree_commit(tree, "test_tree_commit", [g.rev_of('master')])
        dd("commit:", commit)

        got = cmdout(origit,
                     'log',
                     commit,
                     '-n2',
                     '--stat',
                     '--format="%s"',
                     cwd=superp)
        dd(got)

        self.assertEqual([
            '"test_tree_commit"', '', ' imsuperman | 1 -',
            ' 1 file changed, 1 deletion(-)', '"add super"', '',
            ' imsuperman | 1 +', ' 1 file changed, 1 insertion(+)'
        ], got)
Ejemplo n.º 2
0
    def test_tree_new(self):
        g = Git(GitOpt(), cwd=superp)

        tree = g.tree_of('master')
        lines = g.tree_items(tree)

        treeish = g.tree_new(lines)
        got = g.tree_items(treeish)

        self.assertEqual([
            '100644 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\t.gift',
            '100644 blob a668431ae444a5b68953dc61b4b3c30e066535a2\timsuperman',
        ], got)
Ejemplo n.º 3
0
    def test_treeitem_new(self):
        g = Git(GitOpt(), cwd=superp)

        tree = g.tree_of('master')
        lines = g.tree_items(tree, with_size=True)
        itm = g.parse_tree_item(lines[0])
        obj = itm['object']

        got = g.treeitem_new("foo", obj)
        self.assertEqual(
            '100644 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\tfoo', got)

        got = g.treeitem_new("foo", obj, mode='100755')
        self.assertEqual(
            '100755 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\tfoo', got)
Ejemplo n.º 4
0
    def test_parse_tree_item(self):
        g = Git(GitOpt(), cwd=superp)

        tree = g.tree_of('master')
        lines = g.tree_items(tree, with_size=True)

        got = g.parse_tree_item(lines[0])
        self.assertEqual(
            {
                'fn': '.gift',
                'mode': '100644',
                'object': '15d2fff1101916d7212371fea0f3a82bda750f6c',
                'type': 'blob',
                'size': '163',
            }, got)
Ejemplo n.º 5
0
    def test_tree_new(self):
        g = Git(GitOpt(), cwd=superp)

        tree = g.tree_of('master')
        lines = g.tree_items(tree)

        itm = g.parse_tree_item(lines[0])
        obj = itm['object']

        treeish = g.tree_new(lines, 'foo', obj, mode='100755')
        got = g.tree_items(treeish)

        self.assertEqual([
            '100644 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\t.gift',
            '100755 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\tfoo',
            '100644 blob a668431ae444a5b68953dc61b4b3c30e066535a2\timsuperman',
        ], got)
Ejemplo n.º 6
0
    def test_tree_items(self):
        g = Git(GitOpt(), cwd=superp)

        tree = g.tree_of('master')

        lines = g.tree_items(tree)
        self.assertEqual([
            '100644 blob 15d2fff1101916d7212371fea0f3a82bda750f6c\t.gift',
            '100644 blob a668431ae444a5b68953dc61b4b3c30e066535a2\timsuperman'
        ], lines)

        lines = g.tree_items(tree, with_size=True)
        self.assertEqual([
            '100644 blob 15d2fff1101916d7212371fea0f3a82bda750f6c     163\t.gift',
            '100644 blob a668431ae444a5b68953dc61b4b3c30e066535a2       9\timsuperman'
        ], lines)

        lines = g.tree_items(tree, name_only=True)
        self.assertEqual(['.gift', 'imsuperman'], lines)

        lines = g.tree_items(tree, name_only=True, with_size=True)
        self.assertEqual(['.gift', 'imsuperman'], lines)
Ejemplo n.º 7
0
    def test_add_tree(self):

        # TODO opt
        g = Git(GitOpt(), cwd=superp)

        roottreeish = g.tree_of("HEAD")

        dd(
            cmdx(origit,
                 "ls-tree",
                 "87486e2d4543eb0dd99c1064cc87abdf399cde9f",
                 cwd=superp))
        self.assertEqual("87486e2d4543eb0dd99c1064cc87abdf399cde9f",
                         roottreeish)

        # shallow add

        newtree = g.tree_add_obj(roottreeish, "nested", roottreeish)

        files = cmdout(origit,
                       "ls-tree",
                       "-r",
                       "--name-only",
                       newtree,
                       cwd=superp)
        self.assertEqual([
            ".gift",
            "imsuperman",
            "nested/.gift",
            "nested/imsuperman",
        ], files)

        # add nested

        newtree = g.tree_add_obj(newtree, "a/b/c/d", roottreeish)

        files = cmdout(origit,
                       "ls-tree",
                       "-r",
                       "--name-only",
                       newtree,
                       cwd=superp)
        self.assertEqual([
            ".gift",
            "a/b/c/d/.gift",
            "a/b/c/d/imsuperman",
            "imsuperman",
            "nested/.gift",
            "nested/imsuperman",
        ], files)

        # replace nested

        newtree = g.tree_add_obj(newtree, "a/b/c", roottreeish)

        files = cmdout(origit,
                       "ls-tree",
                       "-r",
                       "--name-only",
                       newtree,
                       cwd=superp)
        self.assertEqual([
            ".gift",
            "a/b/c/.gift",
            "a/b/c/imsuperman",
            "imsuperman",
            "nested/.gift",
            "nested/imsuperman",
        ], files)

        # replace a blob with tree

        newtree = g.tree_add_obj(newtree, "a/b/c/imsuperman", roottreeish)

        files = cmdout(origit,
                       "ls-tree",
                       "-r",
                       "--name-only",
                       newtree,
                       cwd=superp)
        self.assertEqual([
            ".gift",
            "a/b/c/.gift",
            "a/b/c/imsuperman/.gift",
            "a/b/c/imsuperman/imsuperman",
            "imsuperman",
            "nested/.gift",
            "nested/imsuperman",
        ], files)

        # replace a blob in mid of path with tree

        newtree = g.tree_add_obj(newtree, "nested/imsuperman/b/c", roottreeish)

        files = cmdout(origit,
                       "ls-tree",
                       "-r",
                       "--name-only",
                       newtree,
                       cwd=superp)
        self.assertEqual([
            ".gift",
            "a/b/c/.gift",
            "a/b/c/imsuperman/.gift",
            "a/b/c/imsuperman/imsuperman",
            "imsuperman",
            "nested/.gift",
            "nested/imsuperman/b/c/.gift",
            "nested/imsuperman/b/c/imsuperman",
        ], files)