コード例 #1
0
def extract(repository, destination, version, debug=False):
    """
    Extract the specified repository/version into the given directory and
    return None.

    :param repository: A string containing the path to the repository to be
     extracted.
    :param destination: A string containing the directory to clone the
     repository into.  Relative to the directory ``gilt`` is running
     in. Must end with a '/'.
    :param version: A string containing the branch/tag/sha to be exported.
    :param debug: An optional bool to toggle debug output.
    :return: None
    """
    with util.saved_cwd():
        if os.path.isdir(destination):
            shutil.rmtree(destination)

        os.chdir(repository)
        _get_version(version, debug)
        cmd = sh.git.bake(
            'checkout-index', force=True, all=True, prefix=destination)
        util.run_command(cmd, debug=debug)
        msg = '  - extracting ({}) {} to {}'.format(version, repository,
                                                    destination)
        util.print_info(msg)
コード例 #2
0
ファイル: shell.py プロジェクト: signed8bit/gilt
def overlay(ctx):  # pragma: no cover
    """Install gilt dependencies """
    args = ctx.obj.get("args")
    filename = args.get("config")
    debug = args.get("debug")
    _setup(filename)

    for c in config.config(filename):
        with fasteners.InterProcessLock(c.lock_file):
            util.print_info("{}:".format(c.name))
            if not os.path.exists(c.src):
                git.clone(c.name, c.git, c.src, debug=debug)
            if c.dst:
                git.extract(c.src, c.dst, c.version, debug=debug)
                post_commands = {c.dst: c.post_commands}
            else:
                git.overlay(c.src, c.files, c.version, debug=debug)
                post_commands = {
                    conf.dst: conf.post_commands
                    for conf in c.files
                }
            # Run post commands if any.
            for dst, commands in post_commands.items():
                for command in commands:
                    msg = "  - running `{}` in {}".format(command, dst)
                    util.print_info(msg)
                    cmd = util.build_sh_cmd(command, cwd=dst)
                    util.run_command(cmd, debug=debug)
コード例 #3
0
def test_run_command_with_debug(temp_dir, capsys):
    cmd = sh.git.bake(version=True)
    util.run_command(cmd, debug=True)

    result, _ = capsys.readouterr()
    x = 'COMMAND: {} --version'.format(sh.git)
    assert x in result
    x = 'PWD: {}'.format(temp_dir)
    assert x in result
コード例 #4
0
def _get_version(version, debug=False):
    """
    Handle switching to the specified version and return None.

    1. Fetch the origin.
    2. Checkout the specified version.
    3. Clean the repository before we begin.
    4. Pull the origin when a branch; _not_ a commit id.

    :param version: A string containing the branch/tag/sha to be exported.
    :param debug: An optional bool to toggle debug output.
    :return: None
    """
    if not any(
        (_has_branch(version, debug), _has_tag(version, debug), _has_commit(
            version, debug))):
        cmd = sh.git.bake('fetch')
        util.run_command(cmd, debug=debug)
    cmd = sh.git.bake('checkout', version)
    util.run_command(cmd, debug=debug)
    cmd = sh.git.bake('clean', '-d', '-x', '-f')
    util.run_command(cmd, debug=debug)
    if _has_branch(version, debug):
        cmd = sh.git.bake('pull', rebase=True, ff_only=True)
        util.run_command(cmd, debug=debug)
コード例 #5
0
ファイル: git.py プロジェクト: signed8bit/gilt
def clone(name, repository, destination, debug=False):
    """Clone the specified repository into a temporary directory and return None.

    :param name: A string containing the name of the repository being cloned.
    :param repository: A string containing the repository to clone.
    :param destination: A string containing the directory to clone the
     repository into.
    :param debug: An optional bool to toggle debug output.
    :return: None
    """
    msg = "  - cloning {} to {}".format(name, destination)
    util.print_info(msg)
    cmd = sh.git.bake("clone", repository, destination)
    util.run_command(cmd, debug=debug)
コード例 #6
0
def _has_branch(version, debug=False):
    """
    Determine a version is a local git branch name or not.

    :param version: A string containing the branch/tag/sha to be determined.
    :param debug: An optional bool to toggle debug output.
    :return: bool
    """
    cmd = sh.git.bake('show-ref', '--verify', '--quiet',
                      "refs/heads/{}".format(version))
    try:
        util.run_command(cmd, debug=debug)
        return True
    except sh.ErrorReturnCode:
        return False
コード例 #7
0
ファイル: git.py プロジェクト: signed8bit/gilt
def _has_commit(version, debug=False):
    """Determine a version is a local git commit sha or not.

    :param version: A string containing the branch/tag/sha to be determined.
    :param debug: An optional bool to toggle debug output.
    :return: bool
    """
    if _has_tag(version, debug) or _has_branch(version, debug):
        return False
    cmd = sh.git.bake("cat-file", "-e", version)
    try:
        util.run_command(cmd, debug=debug)
        return True
    except sh.ErrorReturnCode:
        return False
コード例 #8
0
def test_run_command(capsys):
    cmd = sh.git.bake(version=True)
    util.run_command(cmd)

    result, _ = capsys.readouterr()
    assert '' == result