예제 #1
0
def test_update_ref_delete():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    head = commands.rev_parse(repo=tmp, rev='HEAD')
    eq(head, 'e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27')
    commands.update_ref(
        repo=tmp,
        ref='refs/heads/master',
        newvalue=None,
        )
    got = commands.rev_parse(repo=tmp, rev='refs/heads/master')
    eq(got, None)
예제 #2
0
def test_is_commit_needed_has_change():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    head = commands.rev_parse(repo=tmp, rev='HEAD')
    tree = commands.rev_parse(repo=tmp, rev='HEAD^{tree}')
    got = commands.is_commit_needed(
        repo=tmp,
        tree='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
        parents=[head],
        )
    eq(got, True)
예제 #3
0
파일: test_repo.py 프로젝트: jisqyv/pygitfs
def test_no_empty_commits():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='quux/foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    orig = commands.rev_parse(
        repo=tmp,
        rev='HEAD',
        )

    r = repo.Repository(path=tmp)
    with r.transaction() as p:
        # nothing
        pass

    got = commands.rev_parse(
        repo=tmp,
        rev='HEAD',
        )
    eq(got, orig)
예제 #4
0
def test_is_commit_needed_no_change():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    head = commands.rev_parse(repo=tmp, rev='HEAD')
    tree = commands.rev_parse(repo=tmp, rev='HEAD^{tree}')
    got = commands.is_commit_needed(
        repo=repo,
        tree=tree,
        parents=[head],
        )
    eq(got, False)
예제 #5
0
def test_update_ref_oldvalue_bad():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    head = commands.rev_parse(repo=tmp, rev='HEAD')
    eq(head, 'e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27')
    e = assert_raises(
        # TODO better exception for this
        RuntimeError,
        commands.update_ref,
        repo=tmp,
        ref='HEAD',
        newvalue=head,
        oldvalue='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
        )
    eq(str(e), 'git update-ref failed')
    got = commands.rev_parse(repo=tmp, rev='HEAD')
    eq(got, head)
예제 #6
0
def test_merge_base_disconnected():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    one = commands.rev_parse(repo=tmp, rev='HEAD')
    commands.fast_import(
        repo=tmp,
        ref='refs/heads/another',
        commits=[
            dict(
                message='two',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216235940 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        ),
                    ],
                ),
            ],
        )
    two = commands.rev_parse(repo=tmp, rev='refs/heads/another')
    got = commands.merge_base(
        repo=tmp,
        rev1=one,
        rev2=two,
        )
    eq(got, None)
예제 #7
0
파일: repo.py 프로젝트: jisqyv/pygitfs
 def __enter__(self):
     head = commands.rev_parse(
         repo=self.repo.path,
         rev=self.ref,
         )
     self.original = head
     self.indexfs.rev = head
     return self.indexfs.__enter__()
예제 #8
0
def test_TemporaryIndexFS_rev():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='quux/foo',
                        content='FOO',
                        ),
                    ],
                ),
            dict(
                message='two',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235934 +0300',
                files=[
                    dict(
                        path='quux/foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        mode='100755',
                        ),
                    ],
                ),
            ],
        )
    prev = commands.rev_parse(repo=tmp, rev='HEAD~1')
    t = indexfs.TemporaryIndexFS(repo=tmp, rev='HEAD')
    eq(t.rev, 'HEAD')
    t.rev = prev
    with t as root:
        eq(list(root), [root.child('quux')])
    eq(t.rev, prev)
    tree = commands.rev_parse(repo=tmp, rev='HEAD~1^{tree}')
    eq(t.tree, tree)
예제 #9
0
def check_repository(repo):
    assert os.path.isdir(repo)
    # it's a bare repo
    assert not os.path.exists(os.path.join(repo, '.git'))

    sha = commands.rev_parse(
        rev='refs/heads/master',
        repo=repo,
        )
    assert sha is None, 'Expected no commits yet: %r' % sha

    value = commands.get_symbolic_ref(repo=repo, ref='HEAD')
    eq(value, 'refs/heads/master')
예제 #10
0
파일: test_repo.py 프로젝트: jisqyv/pygitfs
def test_no_empty_commits_initial():
    tmp = maketemp()
    commands.init_bare(tmp)
    r = repo.Repository(path=tmp)
    with r.transaction() as p:
        # nothing
        pass

    got = commands.rev_parse(
        repo=tmp,
        rev='HEAD',
        )
    eq(got, None)
예제 #11
0
def test_enter():
    tmp = maketemp()
    commands.init_bare(tmp)
    r = repo.Repository(tmp)
    with r.transaction() as root:
        with root.child('foo').open('w') as f:
            f.write('FOO')
    head = commands.rev_parse(repo=tmp, rev='HEAD')
    assert head is not None
    with readonly.ReadOnlyGitFS(
        repo=tmp,
        rev='HEAD',
        ) as root:
        eq(root.rev, head)
예제 #12
0
파일: readonly.py 프로젝트: jisqyv/pygitfs
 def __enter__(self):
     """
     Entering a context takes a snapshot.
     """
     rev = commands.rev_parse(
         repo=self.repo,
         rev=self.rev,
         )
     if rev is None:
         # no initial commit but you ask for a snapshot?
         # i'm going to give you the empty tree..
         rev = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
     return self.__class__(
         repo=self.repo,
         rev=rev,
         path=self.path,
         )
예제 #13
0
파일: readonly.py 프로젝트: jisqyv/pygitfs
    def size(self):
        if self.path == '':
            object = commands.rev_parse(
                repo=self.repo,
                rev='%s^{tree}' % self.rev,
                )
        for data in commands.ls_tree(
            repo=self.repo,
            path=self.path,
            treeish=self.rev,
            children=False,
            ):
            object = data['object']
            break

        return commands.get_object_size(
            repo=self.repo,
            object=object,
            )
예제 #14
0
def test_commit_tree():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    index = os.path.join(tmp, 'index')
    commands.fast_import(
        repo=repo,
        ref='refs/heads/import',
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    tree = commands.rev_parse(
        repo=repo,
        rev='refs/heads/import^{tree}',
        )
    eq(tree, 'd513b699a47153aad2f0cb7ea2cb9fde8c177428')

    commit = commands.commit_tree(
        repo=repo,
        tree=tree,
        parents=[],
        message='made some changes',
        committer_name='John Doe',
        committer_email='*****@*****.**',
        committer_date='1216337226 +0300',
        author_name='Bob Smith',
        author_email='*****@*****.**',
        author_date='1216337225 +0300',
        )
    eq(commit, '7a95f3e3276c9704d290375660fb143a3fe0bbcb')
예제 #15
0
def test_rev_parse():
    tmp = maketemp()
    commands.init_bare(tmp)
    commands.fast_import(
        repo=tmp,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            ],
        )
    got = commands.rev_parse(repo=tmp, rev='HEAD')
    eq(got, 'e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27')
예제 #16
0
def test_rev_parse_no_initial():
    tmp = maketemp()
    commands.init_bare(tmp)
    got = commands.rev_parse(repo=tmp, rev='HEAD')
    eq(got, None)
예제 #17
0
def test_read_tree_merge3():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    commands.fast_import(
        repo=repo,
        commits=[
            dict(
                message='one',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    ],
                ),
            dict(
                message='two',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216235940 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        ),
                    ],
                ),
            ],
        )
    one = commands.rev_parse(repo=repo, rev='HEAD~1')
    commands.fast_import(
        repo=repo,
        ref='refs/heads/bar',
        commits=[
            dict(
                parent=one,
                message='three',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235942 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='quux',
                        content='QUUX',
                        ),
                    ],
                ),
            ],
        )

    index = os.path.join(tmp, 'index')
    commands.read_tree(
        repo=repo,
        treeish='HEAD',
        index=index,
        )
    commands.read_tree_merge3(
        repo=repo,
        index=index,
        ancestor=one,
        local='HEAD',
        remote='refs/heads/bar',
        trivial=True,
        )
    g = commands.ls_files(
        repo=repo,
        index=index,
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='add8373108657cb230a5379a6fcdaab73f330642',
            path='bar',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='d96c7efbfec2814ae0301ad054dc8d9fc416c9b5',
            path='foo',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='100644',
            object='b9d4f2faa83cc1ad83ef7493ad6cbf08b086e4c1',
            path='quux',
            ),
        )
    assert_raises(StopIteration, g.next)