def main(): config = get_config() git_tool = GitTool() ( dct_remote_1, dct_project_1, default_remote_1, ) = git_tool.get_manifest_xml_info(filename=config.input1, add_root=True) ( dct_remote_2, dct_project_2, default_remote_2, ) = git_tool.get_manifest_xml_info(filename=config.input2, add_root=True) dct_remote_3 = copy.deepcopy(dct_remote_2) dct_project_3 = copy.deepcopy(dct_project_2) for key, value in dct_project_1.items(): revision = value.get("@revision") if revision: dct_project_3[key]["@revision"] = revision else: dct_project_3[key]["@upstream"] = "12.0" dct_project_3[key]["@dest-branch"] = "12.0" # Update origin to new repo git_tool.generate_repo_manifest( dct_remote=dct_remote_3, dct_project=dct_project_3, output=config.output, default_remote=default_remote_2, )
def main(): config = get_config() git_tool = GitTool() ( dct_remote_1, dct_project_1, default_remote_1, ) = git_tool.get_manifest_xml_info(filename=config.input1, add_root=True) ( dct_remote_2, dct_project_2, default_remote_2, ) = git_tool.get_manifest_xml_info(filename=config.input2, add_root=True) set_project_1 = set(dct_project_1.keys()) set_project_2 = set(dct_project_2.keys()) lst_same_name_normalize = set_project_1.intersection(set_project_2) lst_missing_name_normalize = set_project_2.difference(set_project_1) lst_over_name_normalize = set_project_1.difference(set_project_2) i = 0 total = len(lst_same_name_normalize) for key in lst_missing_name_normalize: i += 1 print(f"{i}/{total} - {key} from input1 not in input2.") i = 0 total = len(lst_over_name_normalize) for key in lst_over_name_normalize: i += 1 print(f"{i}/{total} - {key} from input2 not in input1.") i = 0 total = len(lst_same_name_normalize) for key in lst_same_name_normalize: value1 = dct_project_1.get(key) value2 = dct_project_2.get(key) old_revision = value1.get("@revision", git_tool.default_branch) new_revision = value2.get("@revision", git_tool.default_branch) path1 = value1.get("@path") path2 = value2.get("@path") if path1 != path2: print(f"WARNING id {i}, path of git are different. " f"Input1 {path1}, input2 {path2}") continue i += 1 result = "same" if old_revision == new_revision else "diff" print(f"{i}/{total} - {result} - " f"{path1} {key} old {old_revision} new {new_revision}") default_arg = [f"{old_revision}..{new_revision}"] if old_revision != new_revision: # get git diff repo = Repo(path1) status = repo.git.diff(*default_arg) print(status)
def main(): config = get_config() git_tool = GitTool() lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir, add_repo_root=True) lst_repo_organization = [ git_tool.get_transformed_repo_info_from_url( a.get("url"), repo_path=config.dir, get_obj=True, is_submodule=a.get("is_submodule"), sub_path=a.get("sub_path"), revision=a.get("revision"), clone_depth=a.get("clone_depth")) for a in lst_repo ] # Update origin to new repo if not config.clear: dct_remote, dct_project, _ = git_tool.get_manifest_xml_info( repo_path=config.dir, add_root=True) else: dct_remote = {} dct_project = {} git_tool.generate_repo_manifest(lst_repo_organization, output=f"{config.dir}{config.manifest}", dct_remote=dct_remote, dct_project=dct_project, keep_original=True) git_tool.generate_install_locally()
def main(): config = get_config() git_tool = GitTool() dct_remote, dct_project, default_remote = git_tool.get_manifest_xml_info( filename=config.manifest, add_root=True) default_branch_name = default_remote.get("@revision", git_tool.default_branch) i = 0 total = len(dct_project) for name, project in dct_project.items(): i += 1 path = project.get("@path") print(f"{i}/{total} - {path}") branch_name = project.get("@revision", default_branch_name) organization = project.get("@remote") if not organization: print(f"ERROR missing @remote on project {path}.") continue git_repo = Repo(path) value = git_repo.git.branch("--show-current") if not value: # TODO maybe need to check divergence with local branch and not remote branch commit_head = git_repo.git.rev_parse("HEAD") try: commit_branch = git_repo.git.rev_parse( f"{organization}/{branch_name}") except GitCommandError: print("ERROR Something wrong with this repo.") continue if commit_branch != commit_head: print("WARNING Not on specified branch, got a divergence.") else: print("PASS Not on specified branch, no divergence.") elif branch_name != value: print( f"ERROR, manifest revision is {branch_name} and actual revision is {value}." ) else: print("PASS")
def main(): config = get_config() git_tool = GitTool() dct_remote, dct_project, default_remote = git_tool.get_manifest_xml_info( filename=config.manifest, add_root=True) i = 0 total = len(dct_project) for name, project in dct_project.items(): i += 1 path = project.get("@path") print(f"{i}/{total} - {path}") organization = project.get("@remote", git_tool.default_project_name) try: git_repo = Repo(path) retry(wait_exponential_multiplier=1000, stop_max_delay=15000)(git_repo.git.push)(organization, "--tags") except: print( f"{Fore.RED}ERROR{Style.RESET_ALL} cannot push --tags for path" f" {path} organization {organization}")
def main(): config = get_config() git_tool = GitTool() dct_remote, dct_project, default_remote = git_tool.get_manifest_xml_info( filename=config.manifest, add_root=True) default_branch_name = default_remote.get("@revision", git_tool.default_branch) dct_result = defaultdict(int) i = 0 total = len(dct_project) for name, project in dct_project.items(): i += 1 path = project.get("@path") print(f"{i}/{total} - {path}") branch_name = project.get("@revision", default_branch_name) organization = project.get("@remote", git_tool.default_project_name) try: git_repo = Repo(path) except NoSuchPathError: print(f"{Fore.YELLOW}Warning{Style.RESET_ALL} missing project" f" {path}.") dct_result["WARNING"] += 1 continue value = git_repo.git.branch("--show-current") if not value: # TODO maybe need to check divergence with local branch and not remote branch commit_head = git_repo.git.rev_parse("HEAD") try: commit_branch = git_repo.git.rev_parse( f"{organization}/{branch_name}") except GitCommandError: # Cannot get information if branch_name == commit_head: print(f"{Fore.GREEN}PASS{Style.RESET_ALL} Not on specified" " branch, no divergence") dct_result["PASS"] += 1 else: print(f"{Fore.RED}ERROR{Style.RESET_ALL} manifest revision" f" is {branch_name} and commit {commit_head}.") dct_result["ERROR"] += 1 continue if commit_branch != commit_head: print(f"{Fore.YELLOW}WARNING{Style.RESET_ALL} Not on specified" " branch, got a divergence.") dct_result["WARNING"] += 1 else: print(f"{Fore.GREEN}PASS{Style.RESET_ALL} Not on specified" " branch, no divergence") dct_result["PASS"] += 1 elif branch_name != value: value_hash = git_repo.git.rev_parse(value) if git_repo.git.rev_parse(branch_name) == value_hash: print(f"{Fore.GREEN}PASS{Style.RESET_ALL} Not same branch, no" " divergence") dct_result["PASS"] += 1 else: # Check if the new branch is pushed commit_branch = git_repo.git.rev_parse( f"{organization}/{value}") if commit_branch == value_hash: print(f"{Fore.YELLOW}WARNING{Style.RESET_ALL} New branch" f" '{value}', divergence, but it's push on remote.") dct_result["WARNING"] += 1 else: print(f"{Fore.RED}ERROR{Style.RESET_ALL} manifest revision" f" is {branch_name} and actual revision is {value}.") dct_result["ERROR"] += 1 else: print(f"{Fore.GREEN}PASS{Style.RESET_ALL}") dct_result["PASS"] += 1 str_result = "" if dct_result["PASS"]: str_result += ( f"{Fore.GREEN}PASS: {dct_result['PASS']}{Style.RESET_ALL}") if dct_result["WARNING"]: if str_result: str_result += " " str_result += ( f"{Fore.YELLOW}WARNING: {dct_result['WARNING']}{Style.RESET_ALL}") if dct_result["ERROR"]: if str_result: str_result += " " str_result += ( f"{Fore.RED}ERROR: {dct_result['ERROR']}{Style.RESET_ALL}") print(str_result)