def do_fetch(repo, remotes): ORIGINAL_COLOR = terminal_colors.get_standard_color() report = [] remotes_list = [i for i in remotes if "fetch" in remotes[i]] print("\n* Fetching on %s ..." % repo) hasanyfailed = False try: out = check_output(["git", "-C", repo, "fetch", "--multiple"] + remotes_list) out = "OK." color = terminal_colors.TTY_GREEN except OSError as oser: hasanyfailed = True out = "Failed." color = terminal_colors.TTY_RED except CalledProcessError as cper: hasanyfailed = True out = "Failed." color = terminal_colors.TTY_RED report.append("%s%s: %s%s" % (color, repo, out, ORIGINAL_COLOR)) return hasanyfailed, report
def do_pull(repo, remotes, branches): ORIGINAL_COLOR = terminal_colors.get_standard_color() report = [] remotes_list = [i for i in remotes if "fetch" in remotes[i]] print("\n* Pulling on %s ..." % repo) hasanyfailed = False for rm in remotes_list: for bn in branches: try: out = check_output(["git", "-C", "%s" % repo, "pull", "--ff-only", rm, bn]) out = "OK." color = terminal_colors.TTY_GREEN except OSError as oser: hasanyfailed = True out = "Failed." color = terminal_colors.TTY_RED except CalledProcessError as cper: hasanyfailed = True out = "Failed." color = terminal_colors.TTY_RED report.append("%s%s (remote=%s, branch=%s): %s%s" % (color, repo, rm, bn, out, ORIGINAL_COLOR)) return hasanyfailed, report
def remote_change_url(repo, remote, operation, newpath): ORIGINAL_COLOR = terminal_colors.get_standard_color() report = "" fail = False print("\n* Changing %s's %s remote (%s) ..." % (repo, operation, remote)) try: # currently (september 2016), there is no support on git's side for specifying fetch operations. # so, for now, the operation is ignored #out = check_output(["git", "-C", "%s" % repo, "remote", "set-url", "--%s" % operation, remote, newpath]) out = check_output(["git", "-C", "%s" % repo, "remote", "set-url", remote, newpath]) out = "OK." color = terminal_colors.TTY_GREEN except OSError as oser: fail = True out = "Failed." color = terminal_colors.TTY_RED except CalledProcessError as cper: fail = True out = "Failed." color = terminal_colors.TTY_RED #report = "%sChanging %s's %s remote (%s) to %s: %s%s" % (color, repo, operation, remote, newpath, out, ORIGINAL_COLOR) report = "%sChanging %s's remote (%s) to %s: %s%s" % (color, repo, remote, newpath, out, ORIGINAL_COLOR) return fail, report
def print_report(has_all_passed, report_list): print("\nRESULTS:") for p in report_list: print(p) if has_all_passed: print("\n%sAll operations successful." % terminal_colors.TTY_GREEN) else: print("\n%sNot all operations succeeded." % terminal_colors.TTY_RED) print("%s" % terminal_colors.get_standard_color()) # reset terminal color
def visitor_fetch(repos, options): ORIGINAL_COLOR = terminal_colors.get_standard_color() report = [] all_passed = True for rp in repos: remotes = git_repo_query.get_remotes(rp) remotes = git_visitor_base.filter_remotes(remotes, options) if remotes is None: report.append("%s%s: Failed filtering remotes.%s" % (terminal_colors.TTY_RED, rp, ORIGINAL_COLOR)) continue op_piece, report_piece = git_fetch.do_fetch(rp, remotes) all_passed = all_passed and (not op_piece) for ri in report_piece: report.append(ri) git_visitor_base.print_report(all_passed, report) return all_passed
def visitor_pull(repos, options): ORIGINAL_COLOR = terminal_colors.get_standard_color() report = [] all_passed = True for rp in repos: try: remotes, branches = git_visitor_base.apply_filters(rp, options) except git_visitor_base.gvbexcept as gvbex: all_passed = False report.append("%s%s: %s.%s" % (terminal_colors.TTY_RED, rp, gvbex.message, ORIGINAL_COLOR)) continue op_piece, report_piece = git_pull.do_pull(rp, remotes, branches) all_passed = all_passed and (not op_piece) for ri in report_piece: report.append(ri) git_visitor_base.print_report(all_passed, report) return all_passed
def print_error(msg): print("%s%s%s" % (terminal_colors.TTY_RED, msg, terminal_colors.get_standard_color()))
def print_success(msg): print("%s%s%s" % (terminal_colors.TTY_GREEN, msg, terminal_colors.get_standard_color()))