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"
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"
def print_conflicts(branch, config, git): if has_merge_conflict(branch, config.trunk, git): print(red("{} conflicts with {}".format(branch, config.trunk))) return conflict_found = False for other_branch in config.branches: if has_merge_conflict(branch, other_branch, git): print(red("{} conflicts with {}".format(branch, other_branch))) conflict_found = True if not conflict_found: print_merge_details(branch, config.name, git, known_branches=config.branches)
def rebuild_staging(config, print_details=True, push=True): merge_conflicts = [] not_found = [] all_configs = list(config.span_configs()) context_manager = contextlib.nested( *[OriginalBranch(get_git(path)) for path, _ in all_configs]) with context_manager: for path, config in all_configs: git = get_git(path) git.checkout('-B', config.name, origin(config.trunk), '--no-track') for branch in config.branches: remote = ":" in branch if remote or not has_local(git, branch): if remote: remote_branch = branch.replace(":", "/", 1) else: remote_branch = origin(branch) if not has_remote(git, remote_branch): not_found.append((path, branch)) print " [{cwd}] {branch} NOT FOUND".format( cwd=format_cwd(path), branch=branch, ) continue branch = remote_branch print " [{cwd}] Merging {branch} into {name}".format( cwd=path, branch=branch, name=config.name), try: git.merge(branch, '--no-edit') except sh.ErrorReturnCode_1: merge_conflicts.append((path, branch, config)) try: git.merge("--abort") except sh.ErrorReturnCode_128: pass print "FAIL" else: print "ok" if config.submodules: for submodule in config.submodules: git.add(submodule) git.commit('-m', "update submodule refs", '--no-edit', '--allow-empty') if push and not (merge_conflicts or not_found): for path, config in all_configs: # stupid safety check assert config.name != 'master', path print " [{cwd}] Force pushing to origin {name}".format( cwd=path, name=config.name, ) force_push(get_git(path), config.name) 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, branch, config in merge_conflicts: print "\n[{cwd}] {branch} => {name}".format( cwd=format_cwd(cwd), branch=branch, name=config.name, ) git = get_git(cwd) if print_details: print_merge_details(branch, config.name, git, known_branches=config.branches) if merge_conflicts or not_found: exit(1)
def rebuild_staging(config, print_details=True, push=True): merge_conflicts = [] not_found = [] all_configs = list(config.span_configs()) context_manager = contextlib.nested(*[OriginalBranch(get_git(path)) for path, _ in all_configs]) with context_manager: for path, config in all_configs: git = get_git(path) git.checkout('-B', config.name, origin(config.trunk), '--no-track') for branch in config.branches: remote = ":" in branch if remote or not has_local(git, branch): if remote: remote_branch = branch.replace(":", "/", 1) else: remote_branch = origin(branch) if not has_remote(git, remote_branch): not_found.append((path, branch)) print " [{cwd}] {branch} NOT FOUND".format( cwd=format_cwd(path), branch=branch, ) continue branch = remote_branch print " [{cwd}] Merging {branch} into {name}".format( cwd=path, branch=branch, name=config.name ), try: git.merge(branch, '--no-edit') except sh.ErrorReturnCode_1: merge_conflicts.append((path, branch, config)) try: git.merge("--abort") except sh.ErrorReturnCode_128: pass print "FAIL" else: print "ok" if config.submodules: for submodule in config.submodules: git.add(submodule) git.commit('-m', "update submodule refs", '--no-edit', '--allow-empty') # stupid safety check assert config.name != 'master' if push: print " [{cwd}] Force pushing to origin {name}".format( cwd=path, name=config.name, ) force_push(git, config.name) 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, branch, config in merge_conflicts: print "\n[{cwd}] {branch} => {name}".format( cwd=format_cwd(cwd), branch=branch, name=config.name, ) git = get_git(cwd) if print_details: print_merge_details(branch, config.name, git, known_branches=config.branches) if merge_conflicts or not_found: exit(1)