Example #1
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)
Example #2
0
    def rename(self, new_path):
        if not isinstance(new_path, IndexFS):
            raise CrossDeviceRenameError()

        def g():
            for data in commands.ls_files(repo=self.repo, index=self.index, path=self.path, children=False):
                if data["path"] == self.path:
                    # delete the old one
                    delete = {}
                    delete.update(data)
                    delete["mode"] = "0"
                    yield delete

                    # add the new one
                    data["path"] = new_path.path
                    yield data
                else:
                    prefix = self.path + "/"
                    assert data["path"][: len(prefix)] == prefix

                    # delete the old one
                    delete = {}
                    delete.update(data)
                    delete["mode"] = "0"
                    yield delete

                    # add the new one
                    data["path"] = new_path.path + "/" + data["path"][len(prefix) :]
                    yield data

        commands.update_index(repo=self.repo, index=self.index, files=g())

        self.path = new_path.path
Example #3
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
Example #4
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)
Example #5
0
    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)],
        )
Example #6
0
    def git_mass_set_sha1(self, edits):
        """
        Set the git sha1 for many objects.

        C{edits} is an iterable of 2-tuples, with an C{IndexFS}
        instance and a sha1.

        See also C{git_set_sha1}.
        """

        def g(edits):
            for edit in edits:
                (p, object) = edit
                if not isinstance(p, IndexFS):
                    raise RuntimeError("Path must be an IndexFS path.")
                if p.repo != self.repo or p.index != self.index:
                    raise RuntimeError("Path is from a different IndexFS.")
                yield dict(
                    # TODO mode
                    path=p.path,
                    object=object,
                )

        commands.update_index(repo=self.repo, index=self.index, files=g(edits))
Example #7
0
 def remove(self):
     commands.update_index(repo=self.repo, index=self.index, files=[dict(mode="0", object=40 * "0", path=self.path)])