def restore_state(allcomps, result): for index, comp in enumerate(allcomps): git = GitRepository(comp.remote, comp.local) current_version = result[index][0].split(' ')[1] orig_version = comp.version.name if current_version != orig_version: print(colors.YELLOW + "Restoring " + colors.RESET + "{} to {} from {}.".format( comp.name, colors.GREEN + orig_version + colors.RESET, colors.RED + current_version + colors.RESET)) git.checkout(comp.version.name)
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2dev = [x for x in allcomps if x.name in args.comp_name] for comp in comps2dev: git = GitRepository(comp.remote, comp.local) if comp.develop is None: raise Exception("'develop' branch not specified for {}".format( comp.name)) if not args.quiet: print("Checking out development branch %s in %s" % (colors.YELLOW + comp.develop + colors.RESET, colors.RESET + comp.name + colors.RESET)) git.checkout(comp.develop) output = git.pull()
def run(args): allcomps = MepoState.read_state() for comp in allcomps: git = GitRepository(comp.remote, comp.local) branch = args.branch_name status = git.verify_branch(branch) if status == 0: if args.dry_run: print("Branch %s exists in %s" % (colors.YELLOW + branch + colors.RESET, colors.RESET + comp.name + colors.RESET)) else: if not args.quiet: print("Checking out branch %s in %s" % (colors.YELLOW + branch + colors.RESET, colors.RESET + comp.name + colors.RESET)) git.checkout(branch)
def run(args): allcomps = MepoState.read_state() comps2checkout = _get_comps_to_checkout(args.comp_name, allcomps) for comp in comps2checkout: git = GitRepository(comp.remote, comp.local) branch = args.branch_name if args.b: git.create_branch(branch) if not args.quiet: #print('+ {}: {}'.format(comp.name, branch)) print("Creating and checking out branch %s in %s" % (colors.YELLOW + branch + colors.RESET, colors.RESET + comp.name + colors.RESET)) else: if not args.quiet: print("Checking out %s in %s" % (colors.YELLOW + branch + colors.RESET, colors.RESET + comp.name + colors.RESET)) git.checkout(branch)
def run(args): # This protects against someone using branch without a URL if args.branch and not args.repo_url: raise RuntimeError("The branch argument can only be used with a URL") if args.allrepos and not args.branch: raise RuntimeError( "The allrepos option must be used with a branch/tag.") # If you pass in a config, with clone, it could be outside the repo. # So use the full path passed_in_config = False if args.config: passed_in_config = True args.config = os.path.abspath(args.config) else: # If we don't pass in a config, we need to "reset" the arg to the # default name because we pass args to mepo_init args.config = 'components.yaml' if args.repo_url: p = urlparse(args.repo_url) last_url_node = p.path.rsplit('/')[-1] url_suffix = pathlib.Path(last_url_node).suffix if args.directory: local_clone(args.repo_url, args.branch, args.directory) os.chdir(args.directory) else: if url_suffix == '.git': git_url_directory = pathlib.Path(last_url_node).stem else: git_url_directory = last_url_node local_clone(args.repo_url, args.branch) os.chdir(git_url_directory) # Copy the new file into the repo only if we pass it in if passed_in_config: try: shutil.copy(args.config, os.getcwd()) except shutil.SameFileError as e: pass # This tries to read the state and if not, calls init, # loops back, and reads the state while True: try: allcomps = MepoState.read_state() except StateDoesNotExistError: mepo_init.run(args) continue break max_namelen = len(max([comp.name for comp in allcomps], key=len)) for comp in allcomps: if not comp.fixture: git = GitRepository(comp.remote, comp.local) version = comp.version.name version = version.replace('origin/', '') recurse = comp.recurse_submodules # We need the type to handle hashes in components.yaml type = comp.version.type git.clone(version, recurse, type) if comp.sparse: git.sparsify(comp.sparse) print_clone_info(comp, max_namelen) if args.allrepos: for comp in allcomps: if not comp.fixture: git = GitRepository(comp.remote, comp.local) print("Checking out %s in %s" % (colors.YELLOW + args.branch + colors.RESET, colors.RESET + comp.name + colors.RESET)) git.checkout(args.branch)