@staticmethod
    def from_local_repository(repository_path):
        """ Retrieves the git context from a local git repository.
        :param repository_path: Path to the git repository to retrieve the context from
        """
        try:
            # Special arguments passed to sh: http://amoffat.github.io/sh/special_arguments.html
            sh_special_args = {
                '_tty_out': False,
                '_cwd': repository_path
            }

            # Get info from the local git repository
            # https://git-scm.com/docs/pretty-formats
            commit_msg = sh.git.log("-1", "--pretty=%B", **sh_special_args)
            commit_author_name = sh.git.log("-1", "--pretty=%aN", **sh_special_args)
            commit_author_email = sh.git.log("-1", "--pretty=%aE", **sh_special_args)
            commit_date = sh.git.log("-1", "--pretty=%aD", **sh_special_args)
            commit_parents = sh.git.log("-1", "--pretty=%P", **sh_special_args).split(" ")
            commit_is_merge_commit = len(commit_parents) > 1

            # changed files in last commit
            changed_files_str = sh.git("diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD", **sh_special_args)
        except CommandNotFound:
            error_msg = "'git' command not found. You need to install git to use gitlint on a local repository. " + \
                        "See https://git-scm.com/book/en/v2/Getting-Started-Installing-Git on how to install git."
            raise GitContextError(error_msg)
        except ErrorReturnCode as e:  # Something went wrong while executing the git command
            error_msg = e.stderr.strip()
            if b"Not a git repository" in error_msg:
                error_msg = "{0} is not a git repository.".format(repository_path)
            else:
                error_msg = "An error occurred while executing '{0}': {1}".format(e.full_cmd, error_msg)
            raise GitContextError(error_msg)

        # Create Git commit object with the retrieved info
        changed_files = [changed_file for changed_file in changed_files_str.strip().split("\n")]
        commit_msg_obj = GitCommitMessage.from_full_message(commit_msg)
        commit = GitCommit(commit_msg_obj, author_name=commit_author_name, author_email=commit_author_email,
                           date=commit_date, changed_files=changed_files, parents=commit_parents,
                           is_merge_commit=commit_is_merge_commit)

        # Create GitContext info with the commit object and return
        context = GitContext()
        context.commits.append(commit)
        return context
dataset/ETHPy150Open jorisroovers/gitlint/gitlint/git.py/GitContext.from_local_repository/original