def set_parent_commit(self, commit, check=True):
        """Set this instance to use the given commit whose tree is supposed to
        contain the .gitmodules blob.

        :param commit:
            Commit'ish reference pointing at the root_tree, or None to always point to the
            most recent commit
        :param check:
            if True, relatively expensive checks will be performed to verify
            validity of the submodule.
        :raise ValueError: if the commit's tree didn't contain the .gitmodules blob.
        :raise ValueError:
            if the parent commit didn't store this submodule under the current path
        :return: self"""
        if commit is None:
            self._parent_commit = None
            return self
        # end handle None
        pcommit = self.repo.commit(commit)
        pctree = pcommit.tree
        if self.k_modules_file not in pctree:
            raise ValueError("Tree of commit %s did not contain the %s file" % (commit, self.k_modules_file))
        # END handle exceptions

        prev_pc = self._parent_commit
        self._parent_commit = pcommit

        if check:
            parser = self._config_parser(self.repo, self._parent_commit, read_only=True)
            if not parser.has_section(sm_section(self.name)):
                self._parent_commit = prev_pc
                raise ValueError("Submodule at path %r did not exist in parent commit %s" % (self.path, commit))
            # END handle submodule did not exist
        # END handle checking mode

        # update our sha, it could have changed
        # If check is False, we might see a parent-commit that doens't even contain the submodule anymore.
        # in that case, mark our sha as being NULL
        try:
            self.binsha = pctree[self.path].binsha
        except __HOLE__:
            self.binsha = self.NULL_BIN_SHA
        # end

        self._clear_cache()
        return self
dataset/ETHPy150Open gitpython-developers/GitPython/git/objects/submodule/base.py/Submodule.set_parent_commit