Esempio n. 1
0
    def test_to_args(self):

        cases = (
            (['-C', 'a', '-C', 'b'], None),
            (['-c', 'a=b', '-C', 'b'], [
                '-C',
                'b',
                '-c',
                'a=b',
            ]),
            (['--exec-path=/d'], None),
            (['-p'], ['-p']),
            (['--paginate'], ['-p']),
            (['--no-pager'], None),
            (['--no-pager', '-p'], ['-p']),
            (['--no-replace-objects'], None),
            (['--bare'], None),
            (['--git-dir=a'], None),
            (['--work-tree=a'], None),
            (['--namespace=a'], None),
            (['--super-prefix=a'], None),
        )
        for inp, want in cases:
            if want is None:
                want = inp[:]

            dd(inp)
            dd(want)

            o = GitOpt().parse_args(inp[:])
            rst = o.to_args()
            self.assertEqual(want, rst)
Esempio n. 2
0
    def test_clone(self):
        o = GitOpt().parse_args(['-C', 'a', '--version', '--bar'],
                                additional={'--bar': True})

        p = o.clone()
        p.update({'startpath': 'c'})

        del o.informative_cmds['--version']
        del o.additional['--bar']

        self.assertEqual(['-C', 'a'], o.to_args())
        self.assertEqual(['-C', 'c'], p.to_args())
        self.assertEqual('--version', p.informative_cmds['--version'])
        self.assertEqual('--bar', p.additional['--bar'])
Esempio n. 3
0
    def test_fetch(self):
        g = Git(GitOpt(), cwd=superp)

        g.fetch(wowgitp)
        hsh = g.cmdf('log', '-n1', '--format=%H', 'FETCH_HEAD', flag='0')

        self.assertEqual('6bf37e52cbafcf55ff4710bb2b63309b55bf8e54', hsh)
Esempio n. 4
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)
Esempio n. 5
0
    def test_cmds(self):
        cases = (
            (['-C', 'b', '--version', 'commit', '--version',
              '/p'], ['commit', '--version', '/p'], ['-C', 'b']),
            (['-C', 'b', 'commit', '--version',
              '/p'], ['commit', '--version', '/p'], ['-C', 'b']),
        )

        for inp, wantcmd, wantargs in cases:

            dd(inp)
            dd(wantcmd)
            dd(wantargs)

            o = GitOpt().parse_args(inp[:])
            self.assertEqual(wantcmd, o.cmds)
            self.assertEqual(wantargs, o.to_args())
Esempio n. 6
0
    def test_blob_new(self):
        fwrite(pjoin(superp, "newblob"), "newblob!!!")
        # TODO
        g = Git(GitOpt(), cwd=superp)
        blobhash = g.blob_new("newblob")

        content = cmd0(origit, "cat-file", "-p", blobhash, cwd=superp)
        self.assertEqual("newblob!!!", content)
Esempio n. 7
0
    def test_remote_add(self):
        # TODO
        g = Git(GitOpt(), cwd=superp)
        t = g.remote_get("abc")
        self.assertIsNone(t)

        g.remote_add("newremote", "newremote-url")
        t = g.remote_get("newremote")
        self.assertEqual("newremote-url", t)
Esempio n. 8
0
    def test_remote_get(self):
        # TODO
        g = Git(GitOpt(), cwd=superp)
        t = g.remote_get("abc")
        self.assertIsNone(t)

        cmdx(origit, "remote", "add", "newremote", "newremote-url", cwd=superp)
        t = g.remote_get("newremote")
        self.assertEqual("newremote-url", t)
Esempio n. 9
0
    def test_additional(self):

        cases = ((['-C', 'b', '--foo', 'commit', '--bar',
                   '/p'], ['commit', '--bar', '/p'], ['-C', 'b'], {
                       '--foo': '--foo'
                   }), )

        for inp, wantcmd, wantargs, wantadd in cases:

            dd(inp)
            dd(wantcmd)
            dd(wantargs)
            dd(wantadd)

            o = GitOpt().parse_args(inp[:], additional=['--foo'])
            self.assertEqual(wantcmd, o.cmds)
            self.assertEqual(wantargs, o.to_args())
            self.assertEqual(wantadd, o.additional)
Esempio n. 10
0
    def test_branch_set(self):
        g = Git(GitOpt(), cwd=superp)

        # parent of master
        parent = g.rev_of('master~')

        g.branch_set('master', 'master~')

        self.assertEqual(parent, g.rev_of('master'))
Esempio n. 11
0
    def test_reset_to_commit(self):
        #  * 1315e30 (b2) add b2
        #  | * d1ec654 (base) add base
        #  |/
        #  * 3d7f424 (HEAD -> master, upstream/master, origin/master, dev) a

        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)

        g.cmdf("checkout", 'b2')

        # build index
        fwrite(branch_test_worktree_p, "x", "x")
        g.cmdf('add', 'x')
        fwrite(branch_test_worktree_p, "y", "y")
        g.cmdf('add', 'y')

        # dirty worktree
        fwrite(branch_test_worktree_p, "x", "xx")

        # soft default to HEAD, nothing changed

        g.reset_to_commit('soft')

        out = g.cmdf('diff', '--name-only', '--relative', flag='xo')
        self.assertEqual([
            'x',
        ], out, "dirty worktree")

        out = g.cmdf('diff', '--name-only', '--relative', 'HEAD', flag='xo')
        self.assertEqual(['x', 'y'], out, "compare with HEAD")

        # soft to master

        g.reset_to_commit('soft', 'master')

        out = g.cmdf('diff', '--name-only', '--relative', flag='xo')
        self.assertEqual([
            'x',
        ], out, "dirty worktree")

        out = g.cmdf('diff', '--name-only', '--relative', 'HEAD', flag='xo')
        self.assertEqual([
            'b2',
            'x',
            'y',
        ], out, "compare with HEAD")

        # hard to master

        g.reset_to_commit('hard', 'master')

        out = g.cmdf('diff', '--name-only', '--relative', 'HEAD', flag='xo')
        self.assertEqual([], out, "compare with HEAD")
Esempio n. 12
0
    def test_rev_of(self):
        g = Git(GitOpt(), cwd=superp)
        t = g.rev_of("abc")
        self.assertIsNone(t)

        t = g.rev_of("master")
        self.assertEqual("c3954c897dfe40a5b99b7145820eeb227210265c", t)

        t = g.rev_of("refs/heads/master")
        self.assertEqual("c3954c897dfe40a5b99b7145820eeb227210265c", t)

        t = g.rev_of("c3954c897dfe40a5b99b7145820eeb227210265c")
        self.assertEqual("c3954c897dfe40a5b99b7145820eeb227210265c", t)
Esempio n. 13
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)
Esempio n. 14
0
    def test_branch_default_upstream(self):
        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)
        cases = [
            ('master', 'origin/master'),
            ('dev', 'upstream/master'),
            ('not_a_branch', None),
        ]

        for branch, remote in cases:
            got = g.branch_default_upstream(branch)
            self.assertEqual(remote, got)
Esempio n. 15
0
    def test_worktree_is_clean(self):
        # branch_test_git_p is a git-dir with one commit::
        # * 1d5ae3d (HEAD, origin/master, master) A  a

        # write a ".git" file to specify the git-dir for the containing
        # git-work-tree.
        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)

        self.assertTrue(g.worktree_is_clean())

        fwrite(branch_test_worktree_p, "a", "foobarfoobar")
        self.assertFalse(g.worktree_is_clean())
Esempio n. 16
0
    def setUp(self):
        super(TestGiftPartialInit, self).setUp()

        gg = Gift(GitOpt().update({
            'startpath': [superp],
            'git_dir': None,
            'work_tree': None,
        }))
        gg.init_git_config()

        rel, sb = gg.get_subrepo_config(pjoin(superp, "foo/bar"))
        self.gg = gg
        self.sb = sb
        self.rel = rel
Esempio n. 17
0
    def test_branch_common_base(self):
        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)
        cases = [
            #  (['b2'], (['1315e30ec849dbbe67df3282139c0e0d3fdca606'], ['d1ec6549cffc507a2d41d5e363dcbd23754377c7'])),
            #  (['b2', 'base'], (['1315e30ec849dbbe67df3282139c0e0d3fdca606'], ['d1ec6549cffc507a2d41d5e363dcbd23754377c7'])),
            #  (['b2', 'master'], (['1315e30ec849dbbe67df3282139c0e0d3fdca606'], [])),
            (['b2', 'base'], '3d7f4245f05db036309e9f74430d5479263637ad'),
            (['b2', 'master'], '3d7f4245f05db036309e9f74430d5479263637ad'),
        ]

        for args, want in cases:
            got = g.branch_common_base(*args)
            self.assertEqual(want, got)
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
0
    def test_branch_default_remote(self):
        # branch_test_git_p is a git-dir with one commit::
        # * 1d5ae3d (HEAD, origin/master, master) A  a

        # write a ".git" file to specify the git-dir for the containing
        # git-work-tree.
        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)
        cases = [
            ('master', 'origin'),
            ('dev', 'upstream'),
            ('not_a_branch', None),
        ]

        for branch, remote in cases:
            got = g.branch_default_remote(branch)
            self.assertEqual(remote, got)
Esempio n. 22
0
    def test_head_branch(self):
        # branch_test_git_p is a git-dir with one commit::
        # * 1d5ae3d (HEAD, origin/master, master) A  a

        # write a ".git" file to specify the git-dir for the containing
        # git-work-tree.
        fwrite(branch_test_worktree_p, ".git", "gitdir: ../branch_test_git")

        g = Git(GitOpt(), cwd=branch_test_worktree_p)
        got = g.head_branch()
        self.assertEqual('master', got)

        # checkout to a commit pointing to no branch
        # It should return None
        g.checkout('origin/master')
        got = g.head_branch()
        self.assertIsNone(got)

        g.checkout('master')
Esempio n. 23
0
    def test_informative_opts(self):
        cases = (
            (['--version'], None),
            (['--help'], None),
            (['--html-path'], None),
            (['--info-path'], None),
            (['--man-path'], None),
            (['--exec-path'], None),
            (['--version', '--exec-path'], None),
        )

        for inp, want in cases:
            if want is None:
                want = inp[:]

            dd(inp)
            dd(want)

            o = GitOpt().parse_args(inp[:])
            for k in want:
                self.assertEqual(k, o.informative_cmds[k])
Esempio n. 24
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)
Esempio n. 25
0
    def test_get_subrepo_config(self):
        gg = Gift(GitOpt().update({
            'startpath': [superp],
            'git_dir': None,
            'work_tree': None,
        }))
        gg.init_git_config()

        rel, sb = gg.get_subrepo_config(pjoin(superp, "f"))
        self.assertEqual(('', None), (rel, sb), "inexistent path")

        rel, sb = gg.get_subrepo_config(pjoin(superp, "foo"))
        self.assertEqual(('', None), (rel, sb), "inexistent path foo")

        rel, sb = gg.get_subrepo_config(pjoin(superp, "foo/bar"))
        self.assertEqual('foo/bar', rel)
        self.assertEqual(
            {
                'bareenv': {
                    'GIT_DIR':
                    this_base + '/testdata/supergit/gift/subdir/foo/bar'
                },
                'dir': 'foo/bar',
                'env': {
                    'GIT_DIR':
                    this_base + '/testdata/supergit/gift/subdir/foo/bar',
                    'GIT_WORK_TREE': this_base + '/testdata/super/foo/bar'
                },
                'refhead': 'refs/gift/sub/foo/bar',
                'sub_gitdir': 'gift/subdir/foo/bar',
                'upstream': {
                    'branch': 'master',
                    'name': 'origin',
                    'url': '../bargit'
                }
            }, sb)
Esempio n. 26
0
    def test_update(self):
        o = GitOpt().parse_args(['-C', 'a'])
        o.update({'startpath': 'c'})

        self.assertEqual(['-C', 'c'], o.to_args())
Esempio n. 27
0
    def test_checkout(self):
        g = Git(GitOpt(), cwd=superp)
        g.checkout('master')
        self._fcontent("superman\n", superp, "imsuperman")

        self.assertRaises(CalledProcessError, g.checkout, "foo")
Esempio n. 28
0
    def test_init(self):
        g = Git(GitOpt(), gitdir=supergitp, working_dir=superp)
        g.checkout('master')
        self._fcontent("superman\n", superp, "imsuperman")

        self.assertRaises(CalledProcessError, g.checkout, "foo")
Esempio n. 29
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)