예제 #1
0
def test_update_index():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    index = os.path.join(tmp, 'index')

    sha_foo = commands.write_object(repo=repo, content='FOO')
    sha_bar = commands.write_object(repo=repo, content='BAR')

    assert not os.path.exists(index)
    commands.update_index(
        repo=repo,
        index=index,
        files=[
            dict(
                object=sha_foo,
                path='quux/foo',
                ),
            dict(
                object=sha_bar,
                path='bar',
                ),
            ],
        )
    assert os.path.isfile(index)
    st = os.stat(index)
    assert st.st_size > 0
예제 #2
0
def test_write_tree():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    index = os.path.join(tmp, 'index')
    sha_foo = commands.write_object(repo=repo, content='FOO')
    sha_bar = commands.write_object(repo=repo, content='BAR')
    commands.update_index(
        repo=repo,
        index=index,
        files=[
            dict(
                object=sha_foo,
                path='quux/foo',
                ),
            dict(
                object=sha_bar,
                path='bar',
                ),
            ],
        )

    tree = commands.write_tree(
        repo=repo,
        index=index,
        )
    eq(tree, 'e8abc9dd8c483a4e27598521674ae7a357d2c825')

    g = commands.ls_tree(repo=repo, treeish=tree)
    eq(
        g.next(),
        dict(
            mode='100644',
            type='blob',
            object='add8373108657cb230a5379a6fcdaab73f330642',
            path='bar',
            ),
        )
    eq(
        g.next(),
        dict(
            mode='040000',
            type='tree',
            object='d513b699a47153aad2f0cb7ea2cb9fde8c177428',
            path='quux',
            ),
        )
    assert_raises(StopIteration, g.next)
예제 #3
0
def test_is_commit_needed_no_change():
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    commands.init_bare(repo)
    index = os.path.join(tmp, 'index')
    sha_foo = commands.write_object(repo=repo, content='FOO')
    commands.update_index(
        repo=repo,
        index=index,
        files=[
            dict(
                object=sha_foo,
                path='quux/foo',
                ),
            ],
        )
    tree = commands.write_tree(
        repo=repo,
        index=index,
        )
    got = commands.is_commit_needed(
        repo=repo,
        tree=tree,
        parents=[],
        )
    eq(got, True)
예제 #4
0
def test_get_object_size():
    tmp = maketemp()
    commands.init_bare(tmp)
    sha1 = commands.write_object(repo=tmp, content='FOO')
    eq(sha1, 'd96c7efbfec2814ae0301ad054dc8d9fc416c9b5')
    got = commands.get_object_size(repo=tmp, object=sha1)
    eq(got, 3)
예제 #5
0
def test_batch_cat_file():
    tmp = maketemp()
    commands.init_bare(tmp)
    one = commands.write_object(repo=tmp, content='FOO')
    two = commands.write_object(repo=tmp, content='BAR')
    g = commands.batch_cat_file(repo=tmp)

    got = g.send(one)
    eq(sorted(got.keys()), ['contents', 'object', 'size', 'type'])
    eq(got['type'], 'blob')
    eq(got['size'], 3)
    eq(got['object'], one)
    eq(got['contents'].read(), 'FOO')

    got = g.send(two)
    eq(sorted(got.keys()), ['contents', 'object', 'size', 'type'])
    eq(got['type'], 'blob')
    eq(got['size'], 3)
    eq(got['object'], two)
    eq(got['contents'].read(), 'BAR')

    g.close()
예제 #6
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
 def _close_file(self, f):
     if f.mode not in ["r", "rb"]:
         # flush it so we can open it by name and actually see the
         # data
         f.flush()
     current_users = self.open_files[self.path]
     current_users["users"].remove(f)
     if current_users["writable"] and not current_users["users"]:
         # last user closed a file that has been writable at some
         # point, write it to git object storage and update index
         with file(f.name, "rb") as slurp:
             content = slurp.read()
         os.unlink(f.name)
         object = commands.write_object(repo=self.repo, content=content)
         self.git_set_sha1(object)
         del self.open_files[self.path]
예제 #7
0
파일: indexfs.py 프로젝트: jisqyv/pygitfs
    def mkdir(self, may_exist=False, create_parents=False):
        if not may_exist:
            if self.exists():
                raise OSError(errno.EEXIST, os.strerror(errno.EEXIST))

        # path has no children, therefore it is an empty directory
        # and do not exist in the git world; put in a placeholder
        # file
        if not create_parents:
            # make sure parents exist
            if self.parent() != self:
                if not self.parent().exists():
                    raise OSError(errno.ENOENT, os.strerror(errno.ENOENT))

        empty = commands.write_object(repo=self.repo, content="")
        commands.update_index(
            repo=self.repo,
            index=self.index,
            files=[dict(mode="100644", object=empty, path=self.child(".gitfs-placeholder").path)],
        )
예제 #8
0
def test_batch_cat_file_bad_notfound():
    tmp = maketemp()
    commands.init_bare(tmp)
    one = commands.write_object(repo=tmp, content='FOO')
    g = commands.batch_cat_file(repo=tmp)

    got = g.send('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
    eq(sorted(got.keys()), ['object', 'type'])
    eq(got['type'], 'missing')
    eq(got['object'], 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')

    # it should still be usable after the error
    got = g.send(one)
    eq(sorted(got.keys()), ['contents', 'object', 'size', 'type'])
    eq(got['type'], 'blob')
    eq(got['size'], 3)
    eq(got['object'], one)
    eq(got['contents'].read(), 'FOO')

    g.close()
예제 #9
0
def test_write_object():
    tmp = maketemp()
    commands.init_bare(tmp)
    got = commands.write_object(repo=tmp, content='FOO')
    eq(got, 'd96c7efbfec2814ae0301ad054dc8d9fc416c9b5')