Пример #1
0
def git_fetch(remote=None,
              fetch_all=False,
              sandbox_dir=None,
              debug=False,
              dry_run=False,
              verbose=False):
    """
    Fetch all changes from the remote repository
    """

    cmd_args = ["git", "fetch"]

    if fetch_all:
        cmd_args.append("--all")

    if remote is not None:
        cmd_args.append(unicode(remote))

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                stderr_handler=__handle_generic_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #2
0
def git_submodule_add(url,
                      git_hash=None,
                      force=False,
                      sandbox_dir=None,
                      debug=False,
                      dry_run=False,
                      verbose=False):
    "Add a Git submodule"

    cmd_args = ["git", "submodule", "add"]
    if force:
        cmd_args.append("--force")
    cmd_args.append(url)

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:3]).upper(),
                working_directory=sandbox_dir,
                stderr_handler=CloneHandler.handle_clone_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)

    if git_hash is not None:
        _, name = url.rsplit(os.sep, 1)
        if name.endswith(".git"):
            name = name[:-4]

        git_submodule_update(name,
                             git_hash,
                             sandbox_dir=sandbox_dir,
                             initialize=True,
                             debug=debug,
                             verbose=verbose)
Пример #3
0
def git_remove(filelist,
               cached=False,
               recursive=False,
               sandbox_dir=None,
               debug=False,
               dry_run=False,
               verbose=False):
    "Remove the specified files/directories from the GIT commit index"

    cmd_args = ["git", "rm"]

    if cached:
        cmd_args.append("--cached")
    if recursive:
        cmd_args.append("-r")

    if isinstance(filelist, (tuple, list)):
        cmd_args += filelist
    else:
        cmd_args.append(unicode(filelist))

    handler = RemoveHandler()
    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                returncode_handler=handler.handle_rtncode,
                stderr_handler=handler.handle_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #4
0
def git_autocrlf(sandbox_dir=None, debug=False, dry_run=False, verbose=False):
    "Hack around overeager Git line policing"

    cmd_args = ("git", "config", "--global", "core.autocrlf", "false")

    run_command(cmd_args,
                cmdname="GIT AUTOCRLF",
                working_directory=sandbox_dir,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #5
0
def git_submodule_update(name=None,
                         git_hash=None,
                         initialize=False,
                         merge=False,
                         recursive=False,
                         remote=False,
                         sandbox_dir=None,
                         debug=False,
                         dry_run=False,
                         verbose=False):
    "Update one or more Git submodules"

    if git_hash is not None:
        if name is None:
            raise GitException("Submodule name cannot be None")

        update_args = ("git", "update-index", "--cacheinfo", "160000",
                       unicode(git_hash), unicode(name))

        try:
            run_command(update_args,
                        cmdname=" ".join(update_args[:3]).upper(),
                        working_directory=sandbox_dir,
                        debug=debug,
                        dry_run=dry_run,
                        verbose=verbose)
        except CommandException as cex:
            raise GitException("Cannot update submodule %s index"
                               " to hash %s: %s" % (name, git_hash, cex))

    cmd_args = ["git", "submodule", "update"]
    if initialize:
        cmd_args.append("--init")
    if merge:
        cmd_args.append("--merge")
    if recursive:
        cmd_args.append("--recursive")
    if remote:
        cmd_args.append("--remote")
    if name is not None:
        cmd_args.append(name)

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:3]).upper(),
                working_directory=sandbox_dir,
                stderr_handler=CloneHandler.handle_clone_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #6
0
def git_pull(remote=None,
             branch=None,
             pull_all=False,
             recurse_submodules=None,
             sandbox_dir=None,
             debug=False,
             dry_run=False,
             verbose=False):
    """
    Pull all changes from the remote repository and merge them into the sandbox
    """

    cmd_args = ["git", "pull"]

    if pull_all:
        cmd_args.append("--all")

    if recurse_submodules is not None:
        if recurse_submodules not in PullHandler.OPTIONS:
            raise GitException("Bad --recurse-submodules argument \"%s\"" %
                               (recurse_submodules, ))

        cmd_args += ("--recurse-submodules=%s" % (recurse_submodules, ))

    if remote is not None and branch is not None:
        cmd_args += (unicode(remote), unicode(branch))
    elif remote is not None or branch is not None:
        if remote is None:
            raise GitException("'branch' argument is \"%s\" but 'remote'"
                               " is not specified" % (branch, ))
        raise GitException("'remote' argument is \"%s\" but 'branch'"
                           " is not specified" % (remote, ))

    handler = PullHandler()
    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                returncode_handler=handler.handle_rtncode,
                stderr_finalizer=handler.finalize_stderr,
                stderr_handler=handler.handle_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)

    return handler.branches
Пример #7
0
def git_submodule_init(url=None,
                       sandbox_dir=None,
                       debug=False,
                       dry_run=False,
                       verbose=False):
    "Initialize Git submodules"

    cmd_args = ["git", "submodule", "init"]
    if url is not None:
        cmd_args.append(url)

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:3]).upper(),
                working_directory=sandbox_dir,
                stderr_handler=CloneHandler.handle_clone_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #8
0
def git_add(filelist,
            sandbox_dir=None,
            debug=False,
            dry_run=False,
            verbose=False):
    "Add the specified files/directories to the GIT commit index"

    if isinstance(filelist, (tuple, list)):
        cmd_args = ["git", "add"] + filelist
    else:
        cmd_args = ("git", "add", unicode(filelist))

    handler = AddHandler()
    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                stderr_finalizer=handler.finalize_stderr,
                stderr_handler=handler.handle_stderr,
                debug=debug,
                verbose=verbose)
Пример #9
0
def git_reset(start_point,
              hard=False,
              sandbox_dir=None,
              debug=False,
              dry_run=False,
              verbose=False):
    "Reset the current HEAD to the specified state"

    cmd_args = ["git", "reset"]

    if hard is not None:
        cmd_args.append("--hard")

    cmd_args.append(start_point)

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                stderr_handler=handle_reset_stderr,
                working_directory=sandbox_dir,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #10
0
def git_checkout(branch_name=None,
                 files=None,
                 new_branch=False,
                 recurse_submodules=False,
                 start_point=None,
                 sandbox_dir=None,
                 debug=False,
                 dry_run=False,
                 verbose=False):
    "Check out a branch of the Git repository"

    cmd_args = ["git", "checkout"]

    if files is not None:
        cmd_args.append("--")
        if not isinstance(files, (tuple, list)):
            cmd_args.append(files)
        else:
            cmd_args += files
    else:
        if new_branch:
            cmd_args.append("-b")
        if branch_name is not None:
            cmd_args.append(branch_name)
        if recurse_submodules:
            cmd_args.append("--recurse-submodules")
        if start_point is not None:
            cmd_args.append(unicode(start_point))

    handler = ChkoutHandler()
    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                stderr_finalizer=handler.finalize_stderr,
                stderr_handler=handler.handle_stderr,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)
Пример #11
0
def git_clone(url,
              recurse_submodules=False,
              sandbox_dir=None,
              target_dir=None,
              debug=False,
              dry_run=False,
              verbose=False):
    """
    Clone a Git repository
    sandbox_dir - if specified, create the cloned directory under `sandbox_dir`
    target_dir = if specified, use `target_dir` as the name of the cloned
                 directory
    """

    handler = CloneHandler()
    for new_recurse in CloneHandler.RECURSE_SUPPORTED, False:
        cmd_args = ["git", "clone"]
        if recurse_submodules:
            cmd_args.append(
                "--recurse-submodules" if new_recurse else "--recursive")
        cmd_args.append(url)
        if target_dir is not None:
            cmd_args.append(target_dir)

        handler.clear_recurse_error()

        run_command(cmd_args,
                    cmdname=" ".join(cmd_args[:2]).upper(),
                    working_directory=sandbox_dir,
                    returncode_handler=handler.handle_rtncode,
                    stderr_handler=handler.handle_stderr,
                    debug=debug,
                    dry_run=dry_run,
                    verbose=verbose)

        if not handler.saw_recurse_error:
            break
Пример #12
0
def git_init(bare=False,
             sandbox_dir=None,
             template=None,
             debug=False,
             dry_run=False,
             verbose=False):
    "Add the specified file/directory to the SVN commit"

    cmd_args = ["git", "init"]
    if bare:
        cmd_args.append("--bare")
        sandbox_dir, project = sandbox_dir.rsplit("/", 1)
        if not project.endswith(".git"):
            project += ".git"
        cmd_args.append(project)
    if template is not None:
        cmd_args.append("--template=%s" % (template, ))

    run_command(cmd_args,
                cmdname=" ".join(cmd_args[:2]).upper(),
                working_directory=sandbox_dir,
                debug=debug,
                dry_run=dry_run,
                verbose=verbose)