def check_merges(config):
    merge_conflicts = []
    base_config = config
    for path, config in base_config.span_configs():
        git = get_git(path)
        with OriginalBranch(git):
            git.checkout(config.trunk)
            for branch in config.branches:
                git.checkout(branch)
                print "  [{cwd}] {trunk} => {branch}".format(
                    cwd=format_cwd(path),
                    trunk=config.trunk,
                    branch=branch,
                ),
                if not git_check_merge(config.trunk, branch, git=git):
                    merge_conflicts.append((path, config.trunk, branch))
                    print "FAIL"
                else:
                    print "ok"
    if merge_conflicts:
        print "You must fix the following merge conflicts before rebuilding:"
        for cwd, trunk, branch in merge_conflicts:
            print "  [{cwd}] {trunk} => {branch}".format(
                cwd=format_cwd(cwd),
                branch=branch,
                trunk=trunk,
            )
            git = get_git(cwd)
            print_merge_details(branch, trunk, git)
        exit(1)
    else:
        print "No merge conflicts"
Exemple #2
0
def check_merges(config, print_details=True):
    merge_conflicts = []
    not_found = []
    base_config = config
    for path, config in base_config.span_configs():
        git = get_git(path)
        with OriginalBranch(git):
            trunk = origin(config.trunk)
            git.checkout('-B', config.name, trunk, '--no-track')
            for branch in config.branches:
                if not has_local(git, branch):
                    branch = origin(branch)
                print "  [{cwd}] {trunk} => {branch}".format(
                    cwd=format_cwd(path),
                    trunk=trunk,
                    branch=branch,
                ),
                try:
                    git.checkout(branch)
                except sh.ErrorReturnCode_1 as e:
                    assert ("error: pathspec '%s' did not "
                            "match any file(s) known to git." %
                            branch) in e.stderr, e.stderr
                    not_found.append((path, branch))
                    print "NOT FOUND"
                    continue
                if not git_check_merge(config.name, branch, git=git):
                    merge_conflicts.append(
                        (path, origin(config.trunk), branch))
                    print "FAIL"
                else:
                    print "ok"
    if not_found:
        print "You must remove the following branches before rebuilding:"
        for cwd, branch in not_found:
            print "  [{cwd}] {branch}".format(
                cwd=format_cwd(cwd),
                branch=branch,
            )
    if merge_conflicts:
        print "You must fix the following merge conflicts before rebuilding:"
        for cwd, trunk, branch in merge_conflicts:
            print "  [{cwd}] {trunk} => {branch}".format(
                cwd=format_cwd(cwd),
                branch=branch,
                trunk=trunk,
            )
            git = get_git(cwd)
            if print_details:
                print_merge_details(branch, trunk, git)

    if merge_conflicts or not_found:
        exit(1)
    else:
        print "No merge conflicts"
def check_merges(config, print_details=True):
    merge_conflicts = []
    not_found = []
    base_config = config
    for path, config in base_config.span_configs():
        git = get_git(path)
        with OriginalBranch(git):
            trunk = origin(config.trunk)
            git.checkout('-B', config.name, trunk, '--no-track')
            for branch in config.branches:
                if not has_local(git, branch):
                    branch = origin(branch)
                print "  [{cwd}] {trunk} => {branch}".format(
                    cwd=format_cwd(path),
                    trunk=trunk,
                    branch=branch,
                ),
                try:
                    git.checkout(branch)
                except sh.ErrorReturnCode_1 as e:
                    assert (
                        "error: pathspec '%s' did not "
                        "match any file(s) known to git." % branch) in e.stderr, e.stderr
                    not_found.append((path, branch))
                    print "NOT FOUND"
                    continue
                if not git_check_merge(config.name, branch, git=git):
                    merge_conflicts.append((path, origin(config.trunk), branch))
                    print "FAIL"
                else:
                    print "ok"
    if not_found:
        print "You must remove the following branches before rebuilding:"
        for cwd, branch in not_found:
            print "  [{cwd}] {branch}".format(
                cwd=format_cwd(cwd),
                branch=branch,
            )
    if merge_conflicts:
        print "You must fix the following merge conflicts before rebuilding:"
        for cwd, trunk, branch in merge_conflicts:
            print "  [{cwd}] {trunk} => {branch}".format(
                cwd=format_cwd(cwd),
                branch=branch,
                trunk=trunk,
            )
            git = get_git(cwd)
            if print_details:
                print_merge_details(branch, trunk, git)

    if merge_conflicts or not_found:
        exit(1)
    else:
        print "No merge conflicts"