Exemple #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)
Exemple #2
0
def test_for_each_ref_sort():
    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',
                        ),
                    ],
                ),
            ],
        )
    commands.update_ref(
        repo=tmp,
        ref='refs/heads/quux',
        newvalue='HEAD',
        oldvalue=40*'0',
        )
    got = commands.for_each_ref(
        repo=tmp,
        sort='-refname',
        )
    got = iter(got)
    eq(got.next(), dict(refname='refs/heads/quux'))
    eq(got.next(), dict(refname='refs/heads/master'))
    assert_raises(StopIteration, got.next)
Exemple #3
0
 def __exit__(self, type_, value, traceback):
     ret = self.indexfs.__exit__(type_, value, traceback)
     assert not ret, \
         "TemporaryIndexFS must not eat the exception."
     tree = self.indexfs.tree
     del self.indexfs
     if (type_ is None
         and value is None
         and traceback is None):
         # no exception -> commit transaction
         assert tree is not None, \
             "TemporaryIndexFS must write the tree."
         parents = []
         if self.original is not None:
             parents.append(self.original)
         if not commands.is_commit_needed(
             repo=self.repo.path,
             tree=tree,
             parents=parents,
             ):
             return
         self.commit = commands.commit_tree(
             repo=self.repo.path,
             tree=tree,
             parents=parents,
             message='pygitfs',
             committer_name='pygitfs',
             committer_email='pygitfs@invalid',
             )
         try:
             commands.update_ref(
                 repo=self.repo.path,
                 ref=self.ref,
                 newvalue=self.commit,
                 oldvalue=self.original,
                 reason='pygitfs transaction commit',
                 )
         except RuntimeError:
             # TODO this could be caused by pretty much anything
             # from OOM to invalid input, but as there's no way to
             # tell (with current git), we'll just assume it's
             # always caused by race condition..
             raise TransactionRaceLostError()
Exemple #4
0
def test_for_each_ref_fields():
    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',
                        ),
                    ],
                ),
            dict(
                message='two',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216235940 +0300',
                files=[
                    dict(
                        path='foo',
                        content='FOO',
                        ),
                    dict(
                        path='bar',
                        content='BAR',
                        ),
                    ],
                ),
            ],
        )
    commands.update_ref(
        repo=tmp,
        ref='refs/heads/quux',
        newvalue='HEAD~1',
        oldvalue=40*'0',
        )
    got = commands.for_each_ref(
        repo=tmp,
        fields=['refname', 'objecttype', 'objectname'],
        )
    got = iter(got)
    eq(
        got.next(),
        dict(
            refname='refs/heads/master',
            objecttype='commit',
            objectname='27f952fd48ce824454457b9f28bb97091bc5422e',
            ),
        )
    eq(
        got.next(),
        dict(
            refname='refs/heads/quux',
            objecttype='commit',
            objectname='e1b2f3253b18e7bdbd38db0cf295e6b3b608bb27',
            ),
        )
    assert_raises(StopIteration, got.next)