Example #1
0
def _multi_execute(argslist, subdir, error_msg):
    """Executes a series of commands in subprocesses.

    Args:
        argslist (list): of `tuple` with `(arglist, e_analyzer)` to pass to :func:`execute`.
        subdir (str): path to the folder to execute in.
        error_msg (str): error message to display if any of the commands fails.

    Returns:
        bool: `True` if the execution was successful for all steps.
    """
    for atup in argslist:
        if isinstance(atup, tuple):
            a, e_analyzer = atup
        else:
            a, e_analyzer = atup, None

        log.debug(f"Executing {a} in {subdir}")
        o = execute(a, subdir, printerr=False)
        log.debug(o)
        error = False
        if e_analyzer is not None:
            error = e_analyzer(o)
            log.debug(o, error)
        elif len(o["error"]) > 0:
            error = True

        if error:
            msg.warn(error_msg)
            return False
    else:
        return True
Example #2
0
def is_detached(folder):
    """Determines if the specified folder is in a detached HEAD state in `git`.

    Args:
        folder (str): path to the repository to check.
    """
    args = ["git", "status"]
    output = execute(args, folder)
    return "HEAD detached at" in output["output"][0]
Example #3
0
def get_branch_name(folder):
    """Gets the branch name for the repo at folder.
    """
    args = ["git", "status"]
    output = execute(args, folder, printerr=False)
    matching = [l for l in output["output"] if "On branch" in l]
    if len(matching) == 1:
        return matching[0].split()[-1]
    else:
        return None
Example #4
0
def ls_submodules(folder):
    """Lists all the submodules in the given folder.
    """
    sm_args = ["git", "submodule", "status"]
    sm_output = execute(sm_args)
    log.debug(
        f"Finding submodules in {folder} from process output {sm_output}")
    submodules = []
    for line in sm_output["output"]:
        parts = line.split()
        submodules.append(parts[1][3:])

    return submodules
Example #5
0
def check_uncommitted_changes(folder=None):
    """Checks if the given the repository at `folder` has uncommitted changes.

    Returns:
        bool: `True` if there are changes that need to be committed.
    """
    if folder is None:
        folder = reporoot

    args = ["git", "status", "."]
    log.info(f"Checking status for repository in {folder}.")
    result = execute(args, folder, printerr=False)
    has_changes = len([
        l for l in result["output"]
        if "not staged" in l or "Changes to be committed" in l
    ]) > 0

    if has_changes:
        msg.warn(
            f"There are uncommitted changes in the repository at {folder}.")
        msg.std('\n'.join(result["output"]))
        return True

    return False