예제 #1
0
    def get(cls, id, treeish=None):
        """
        Gets the object associated with the given id
        """
        workspace = cls._meta.workspace
        path = cls._meta.get_data_path(id)

        if treeish:
            tree = utils.treeish_to_tree(workspace.repo, treeish)
        else:
            tree = workspace.index

        msg = "{} with id {}{} does not exist."
        name = cls._meta.model_name
        revname = treeish and '@{}'.format(treeish) or ''
        msg = msg.format(name, id, revname)

        if not tree:
            raise exceptions.DoesNotExist(msg)

        try:
            blob = tree[path].oid
        except KeyError:
            raise exceptions.DoesNotExist(msg)
        data = workspace.repo[blob].data

        return cls._meta.serializer.deserialize(workspace, data, blob)
예제 #2
0
    def update_index(self, treeish):
        """Sets the index to the current branch or to the given treeish"""
        # Don't change the index if there are pending changes.
        if self.index and self.has_changes():
            msg = "Cannot checkout a different branch with pending changes"
            raise exceptions.RepositoryError(msg)

        tree = utils.treeish_to_tree(self.repo, treeish)

        if treeish.startswith('refs/heads'):
            # if treeish is a head ref, update head
            self.head = treeish
        else:
            # otherwise, we're in "detached head" mode
            self.head = None

        self.index = tree
예제 #3
0
    def update_index(self, treeish):
        """Sets the index to the current branch or to the given treeish"""
        # Don't change the index if there are pending changes.
        if self.index and self.has_changes():
            msg = "Cannot checkout a different branch with pending changes"
            raise exceptions.RepositoryError(msg)

        tree = utils.treeish_to_tree(self.repo, treeish)

        if treeish.startswith('refs/heads'):
            # if treeish is a head ref, update head
            self.head = treeish
        else:
            # otherwise, we're in "detached head" mode
            self.head = None

        self.index = tree