Esempio n. 1
0
def gitext_update(recursive, gitsvn, reset):
    """Update the working copy cloning externals if needed and create the desired layout using symlinks
    """
    from git_externals import externals_sanity_check, root_path, is_workingtree_clean, foreach_externals, gitext_up

    externals_sanity_check()
    root = root_path()

    if reset:
        git('reset', '--hard')

    # Aggregate in a list the `clean flags` of all working trees (root + externals)
    clean = [is_workingtree_clean(root, fail_on_empty=False)]
    foreach_externals(root,
        lambda u, p, r: clean.append(is_workingtree_clean(p, fail_on_empty=False)),
        recursive=recursive)

    if reset or all(clean):
        # Proceed with update if everything is clean
        try:
            gitext_up(recursive, reset=reset, use_gitsvn=gitsvn)
        except ProgError as e:
            error(str(e), exitcode=e.errcode)
    else:
        echo("Cannot perform git externals update because one or more repositories contain some local modifications")
        echo("Run:\tgit externals status\tto have more information")
Esempio n. 2
0
def gitext_update(recursive, gitsvn, reset):
    """Update the working copy cloning externals if needed and create the desired layout using symlinks
    """
    from git_externals import externals_sanity_check, root_path, is_workingtree_clean, foreach_externals, gitext_up

    externals_sanity_check()
    root = root_path()

    if reset:
        git('reset', '--hard')

    # Aggregate in a list the `clean flags` of all working trees (root + externals)
    clean = [is_workingtree_clean(root, fail_on_empty=False)]
    foreach_externals(root,
                      lambda u, p, r: clean.append(
                          is_workingtree_clean(p, fail_on_empty=False)),
                      recursive=recursive)

    if reset or all(clean):
        # Proceed with update if everything is clean
        try:
            gitext_up(recursive, reset=reset, use_gitsvn=gitsvn)
        except ProgError as e:
            error(str(e), exitcode=e.errcode)
    else:
        echo(
            "Cannot perform git externals update because one or more repositories contain some local modifications"
        )
        echo("Run:\tgit externals status\tto have more information")
Esempio n. 3
0
def gitext_freeze(externals, messages):
    """Freeze the externals revision"""
    from git_externals import load_gitexts, dump_gitexts, foreach_externals_dir, root_path, resolve_revision
    git_externals = load_gitexts()
    repo_root = root_path()
    re_from_git_svn_id = re.compile("git-svn-id:.*@(\d+)")
    re_from_svnversion = re.compile("(\d+):(\d+)")

    def get_version(rel_url, ext_path, refs):
        if 'tag' in refs:
            return

        bare_svn = False
        if git_externals[rel_url]["vcs"] == "svn":
            revision = command('svnversion', '-c').strip()
            match = re_from_svnversion.search(revision)
            if match:
                revision = "svn:r" + match.group(2)  # 565:56555 -> svn:r56555
                bare_svn = True
            else:
                message = git("log", "--format=%b", "--grep", "git-svn-id:",
                              "-1")
                match = re_from_git_svn_id.search(message)
                if match:
                    revision = "svn:r" + match.group(1)
                else:
                    here = os.path.relpath(os.getcwd(), repo_root)
                    error(
                        "Unsupported external format, svn or git-svn repo expected:\n\t{}"
                        .format(here))
        else:
            branch_name = current_branch()
            remote_name = git("config", "branch.%s.remote" % branch_name)
            revision = git("log", "%s/%s" % (remote_name, branch_name), "-1",
                           "--format=%H")

        info("Freeze {0} at {1}".format(rel_url, revision))
        if messages and not bare_svn:
            old = resolve_revision(git_externals[rel_url]["ref"])
            new = resolve_revision(revision)
            git("log",
                "--format=- %h %s",
                "{}..{}".format(old, new),
                capture=False)
        git_externals[rel_url]["ref"] = revision

    foreach_externals_dir(repo_root, get_version, only=externals)

    dump_gitexts(git_externals)
Esempio n. 4
0
def gitext_st(porcelain, verbose, externals):
    """Call git status on the given externals"""
    from git_externals import foreach_externals_dir, root_path, \
                              is_workingtree_clean, get_repo_name

    def get_status(rel_url, ext_path, targets):
        try:
            if porcelain:
                echo(rel_url)
                click.echo(git('status', '--porcelain'))
            elif verbose or not is_workingtree_clean(ext_path):
                info("External {}".format(get_repo_name(rel_url)))
                echo(git('status', '--untracked-files=no' if not verbose else ''))
        except CommandError as err:
            error(str(err), exitcode=err.errcode)

    foreach_externals_dir(root_path(), get_status, recursive=True, only=externals)
Esempio n. 5
0
def gitext_foreach(recursive, subcommand):
    """Evaluates an arbitrary shell command in each checked out external
    """
    from git_externals import externals_sanity_check, get_repo_name, foreach_externals_dir, root_path

    externals_sanity_check()

    def run_command(rel_url, ext_path, targets):
        try:
            info("External {}".format(get_repo_name(rel_url)))
            output = decode_utf8(command(*subcommand))
            info("Ok: CWD: {}, cmd: {}".format(os.getcwd(), subcommand))
            echo(output)
        except CommandError as err:
            info("Command error {} CWD: {}, cmd: {}".format(err, os.getcwd(), subcommand))
            error(str(err), exitcode=err.errcode)

    foreach_externals_dir(root_path(), run_command, recursive=recursive)
Esempio n. 6
0
def gitext_foreach(recursive, subcommand):
    """Evaluates an arbitrary shell command in each checked out external
    """
    from git_externals import externals_sanity_check, get_repo_name, foreach_externals_dir, root_path

    externals_sanity_check()

    def run_command(rel_url, ext_path, targets):
        try:
            info("External {}".format(get_repo_name(rel_url)))
            output = decode_utf8(command(*subcommand))
            info("Ok: CWD: {}, cmd: {}".format(os.getcwd(), subcommand))
            echo(output)
        except CommandError as err:
            info("Command error {} CWD: {}, cmd: {}".format(
                err, os.getcwd(), subcommand))
            error(str(err), exitcode=err.errcode)

    foreach_externals_dir(root_path(), run_command, recursive=recursive)
Esempio n. 7
0
def gitext_freeze(externals, messages):
    """Freeze the externals revision"""
    from git_externals import load_gitexts, dump_gitexts, foreach_externals_dir, root_path, resolve_revision
    git_externals = load_gitexts()
    repo_root = root_path()
    re_from_git_svn_id = re.compile("git-svn-id:.*@(\d+)")
    re_from_svnversion = re.compile("(\d+):(\d+)")

    def get_version(rel_url, ext_path, refs):
        if 'tag' in refs:
            return

        bare_svn = False
        if git_externals[rel_url]["vcs"] == "svn":
            revision = command('svnversion', '-c').strip()
            match = re_from_svnversion.search(revision)
            if match:
                revision = "svn:r" + match.group(2)  # 565:56555 -> svn:r56555
                bare_svn = True
            else:
                message = git("log", "--format=%b", "--grep", "git-svn-id:", "-1")
                match = re_from_git_svn_id.search(message)
                if match:
                    revision = "svn:r" + match.group(1)
                else:
                    here = os.path.relpath(os.getcwd(), repo_root)
                    error("Unsupported external format, svn or git-svn repo expected:\n\t{}".format(here))
        else:
            branch_name = current_branch()
            remote_name = git("config", "branch.%s.remote" % branch_name)
            revision = git("log", "%s/%s" % (remote_name, branch_name), "-1", "--format=%H")

        info("Freeze {0} at {1}".format(rel_url, revision))
        if messages and not bare_svn:
            old = resolve_revision(git_externals[rel_url]["ref"])
            new = resolve_revision(revision)
            git("log", "--format=- %h %s", "{}..{}".format(old, new), capture=False)
        git_externals[rel_url]["ref"] = revision

    foreach_externals_dir(repo_root, get_version, only=externals)

    dump_gitexts(git_externals)
Esempio n. 8
0
def gitext_st(porcelain, verbose, externals):
    """Call git status on the given externals"""
    from git_externals import foreach_externals_dir, root_path, \
                              is_workingtree_clean, get_repo_name

    def get_status(rel_url, ext_path, targets):
        try:
            if porcelain:
                echo(rel_url)
                click.echo(git('status', '--porcelain'))
            elif verbose or not is_workingtree_clean(ext_path):
                info("External {}".format(get_repo_name(rel_url)))
                echo(
                    git('status',
                        '--untracked-files=no' if not verbose else ''))
        except CommandError as err:
            error(str(err), exitcode=err.errcode)

    foreach_externals_dir(root_path(),
                          get_status,
                          recursive=True,
                          only=externals)
Esempio n. 9
0
def gitext_freeze(externals):
    """Freeze the externals revision"""
    from git_externals import load_gitexts, dump_gitexts, foreach_externals_dir, root_path
    git_externals = load_gitexts()
    re_from_git_svn_id = re.compile("git-svn-id:.*@(\d+)")
    re_from_svnversion = re.compile("(\d+):(\d+)")

    def get_version(rel_url, ext_path, refs):
        if 'tag' in refs:
            return

        if git_externals[rel_url]["vcs"] == "svn":
            revision = command('svnversion', '-c').strip()
            match = re_from_svnversion.search(revision)
            if match:
                revision = "svn:r" + match.group(2)  # 565:56555 -> svn:r56555
            else:
                message = git("log", "--format=%b", "--grep", "git-svn-id:",
                              "-1")
                match = re_from_git_svn_id.search(message)
                if match:
                    revision = "svn:r" + match.group(1)
                else:
                    error(
                        "Unsupported external format, should be svn or git-svn repo"
                    )
        else:
            branch_name = current_branch()
            remote_name = git("config", "branch.%s.remote" % branch_name)
            revision = git("log", "%s/%s" % (remote_name, branch_name), "-1",
                           "--format=%H")

        info("Freeze {0} at {1}".format(rel_url, revision))
        git_externals[rel_url]["ref"] = revision

    foreach_externals_dir(root_path(), get_version, only=externals)

    dump_gitexts(git_externals)