How to use the gitman.exceptions.ShellError function in gitman

To help you get started, we’ve selected a few gitman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jacebrowning / gitman / gitman / git.py View on Github external
git('update-index', '-q', '--refresh', _show=False)

        # Check for uncommitted changes
        git('diff-index', '--quiet', 'HEAD', _show=_show)

        # Check for untracked files
        lines = git('ls-files', '--others', '--exclude-standard', _show=_show)

    except ShellError:
        status = True

    else:
        status = bool(lines) and include_untracked

    if status and display_status:
        with suppress(ShellError):
            lines = git('status', _show=True)
            common.show(*lines, color='git_changes')

    return status
github jacebrowning / gitman / gitman / git.py View on Github external
def valid():
    """Confirm the current directory is a valid working tree.

    Checking both the git working tree exists and that the top leve
    directory path matches the current directory path.
    """

    log.debug("Checking for a valid working tree...")

    try:
        git('rev-parse', '--is-inside-work-tree', _show=False)
    except ShellError:
        return False

    log.debug("Checking for a valid git top level...")
    gittoplevel = git('rev-parse', '--show-toplevel', _show=False)
    currentdir = pwd(_show=False)

    status = False
    if gittoplevel[0] == currentdir:
        status = True
    else:
        log.debug(
            "git top level: %s != current working directory: %s",
            gittoplevel[0],
            currentdir,
        )
        status = False
github jacebrowning / gitman / gitman / shell.py View on Github external
if _ignore:
        log.debug("Ignored error from call to '%s'", name)
        return output

    message = (
        "An external program call failed." + "\n\n"
        "In working directory: " + os.getcwd() + "\n\n"
        "The following command produced a non-zero return code:"
        + "\n\n"
        + CMD_PREFIX
        + program
        + "\n"
        + command.stdout.strip()
    )
    raise ShellError(message, program=program, output=output)
github jacebrowning / gitman / gitman / models / source.py View on Github external
# Enter the working tree
        shell.cd(self.name)
        if not git.valid():
            raise self._invalid_repository

        # Check for scripts
        if not self.scripts:
            common.show("(no scripts to run)", color='shell_info')
            common.newline()
            return

        # Run all scripts
        for script in self.scripts:
            try:
                lines = shell.call(script, _shell=True)
            except exceptions.ShellError as exc:
                common.show(*exc.output, color='shell_error')
                cmd = exc.program
                if force:
                    log.debug("Ignored error from call to '%s'", cmd)
                else:
                    msg = "Command '{}' failed in {}".format(cmd, os.getcwd())
                    raise exceptions.ScriptFailure(msg)
            else:
                common.show(*lines, color='shell_output')
        common.newline()
github jacebrowning / gitman / gitman / exceptions.py View on Github external
def __init__(self, *args, **kwargs):
        self.program = kwargs.pop('program', None)
        self.output = kwargs.pop('output', None)
        super().__init__(*args, **kwargs)  # type: ignore


class InvalidRepository(RuntimeError):
    """Raised when there is a problem with the checked out directory."""


class UncommittedChanges(RuntimeError):
    """Raised when uncommitted changes are not expected."""


class ScriptFailure(ShellError):
    """Raised when post-install script has a non-zero exit code."""