

@staticmethod
def from_local_repository(repository_path):
    ' Retrieves the git context from a local git repository.\n        :param repository_path: Path to the git repository to retrieve the context from\n        '
    try:
        sh_special_args = {
            '_tty_out': False,
            '_cwd': repository_path,
        }
        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_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:
        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)
    changed_files = [sh_special_args 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)
    context = GitContext()
    context.commits.append(commit)
    return context

dataset/ETHPy150Open jorisroovers/gitlint/gitlint/git.py GitContext.from_local_repository/VarMisuse@236/563 `changed_file`->`sh_special_args`