Execute a git command and return the output.

    Catches CalledProcessErrors and OSErrors, wrapping them
    in a more useful :class:`~simpl.exceptions.SimplGitCommandError`.

    Raises :class:`~simpl.exceptions.SimplGitCommandError` if the command
    fails. Returncode and output from the attempt can be found in the
    SimplGitCommandError attributes.

def execute_git_command(command, repo_dir=None):
    """Execute a git command and return the output.

    Catches CalledProcessErrors and OSErrors, wrapping them
    in a more useful :class:`~simpl.exceptions.SimplGitCommandError`.

    Raises :class:`~simpl.exceptions.SimplGitCommandError` if the command
    fails. Returncode and output from the attempt can be found in the
    SimplGitCommandError attributes.
    """
    try:
        output = shell.execute(command, cwd=repo_dir)
    except exceptions.SimplCalledProcessError as err:
        raise exceptions.SimplGitCommandError(err.returncode, err.cmd,
                                              output=err.output)
    except OSError as err:
        # OSError's errno *is not* the returncode
        raise exceptions.SimplGitCommandError(
            127, command, output=repr(err), oserror=err)
    else:
        return output