def run(args): allcomps = MepoState.read_state() comps2fetch = _get_comps_to_list(args.comp_name, allcomps) for comp in comps2fetch: git = GitRepository(comp.remote, comp.local) print("Fetching %s" % colors.YELLOW + comp.name + colors.RESET) git.fetch(args)
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2stg = [x for x in allcomps if x.name in args.comp_name] for comp in comps2stg: git = GitRepository(comp.remote, comp.local) stage_files(git, comp, args.untracked)
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2commit = [x for x in allcomps if x.name in args.comp_name] tf_file = None # Pop up an editor if a message is not provided if not args.message: EDITOR = git_var('GIT_EDITOR') initial_message = b"" # set up the file # Use delete=False to keep the file around as we send the file name to git commit -F tf = tempfile.NamedTemporaryFile(delete=False) tf_file = tf.name tf.write(initial_message) tf.flush() subprocess.call([EDITOR, tf.name]) for comp in comps2commit: git = GitRepository(comp.remote, comp.local) if args.all: stage_files(git, comp, commit=True) staged_files = git.get_staged_files() if staged_files: git.commit_files(args.message,tf_file) for myfile in staged_files: print('+ {}: {}'.format(comp.name, myfile)) # Now close and by-hand delete the temp file if not args.message: tf.close() os.unlink(tf.name)
def run(args): print('Checking status...'); sys.stdout.flush() allcomps = MepoState.read_state() pool = mp.Pool() atexit.register(pool.close) result = pool.map(check_component_status, allcomps) print_status(allcomps, result)
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2appst = [x for x in allcomps if x.name in args.comp_name] for comp in comps2appst: git = GitRepository(comp.remote, comp.local) git.apply_stash()
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2tagpush = _get_comps_to_list(args.comp_name, allcomps) for comp in comps2tagpush: git = GitRepository(comp.remote, comp.local) git.push_tag(args.tag_name, args.force) print(f'Pushed tag {args.tag_name} to {comp.name}')
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2deltg = _get_comps_to_list(args.comp_name, allcomps) for comp in comps2deltg: git = GitRepository(comp.remote, comp.local) git.delete_tag(args.tag_name) print('- {}: {}'.format(comp.name, args.tag_name))
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2showst = [x for x in allcomps if x.name in args.comp_name] for comp in comps2showst: git = GitRepository(comp.remote, comp.local) result = git.show_stash(args.patch) print(result)
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2crtbr = [x for x in allcomps if x.name in args.comp_name] for comp in comps2crtbr: git = GitRepository(comp.remote, comp.local) git.create_branch(args.branch_name) print('+ {}: {}'.format(comp.name, args.branch_name))
def run(args): allcomps = MepoState.read_state() comps2unstg = _get_comps_to_unstage(args.comp_name, allcomps) for comp in comps2unstg: git = GitRepository(comp.remote, comp.local) staged_files = git.get_staged_files() for myfile in staged_files: git.unstage_file(myfile) print('- {}: {}'.format(comp.name, myfile))
def run(args): allcomps = MepoState.read_state() verify.valid_components(args.comp_name, allcomps) comps2push = [x for x in allcomps if x.name in args.comp_name] for comp in comps2push: git = GitRepository(comp.remote, comp.local) output = git.push() print('----------\nPushed: {}\n----------'.format(comp.name)) print(output)
def run(args): print('Diffing...'); sys.stdout.flush() allcomps = MepoState.read_state() comps2diff = _get_comps_to_diff(args.comp_name, allcomps) for comp in comps2diff: result = check_component_diff(comp, args) if result: print_diff(comp, args, result)
def run(args): allcomps = MepoState.read_state() max_namelen = len(max([x.name for x in allcomps], key=len)) FMT = '{:<%s.%ss} | {:<s}' % (max_namelen, max_namelen) for comp in allcomps: git = GitRepository(comp.remote, comp.local) output = git.list_stash().rstrip().split('\n') print(FMT.format(comp.name, output[0])) for line in output[1:]: print(FMT.format('', line))
def run(args): allcomps = MepoState.read_state() comps2list = _get_comps_to_list(args.comp_name, allcomps) max_namelen = len(max([x.name for x in comps2list], key=len)) FMT = '{:<%s.%ss} | {:<s}' % (max_namelen, max_namelen) for comp in comps2list: git = GitRepository(comp.remote, comp.local) output = git.list_branch(args.all).rstrip().split('\n') print(FMT.format(comp.name, output[0])) for line in output[1:]: print(FMT.format('', line))
def run(args): allcomps = MepoState.read_state() for comp in allcomps: _update_comp(comp) MepoState.write_state(allcomps) complist = dict() relpath_start = MepoState.get_root_dir() for comp in allcomps: complist.update(comp.to_dict(relpath_start)) config_file_root_dir = os.path.join(relpath_start, args.config_file) ConfigFile(config_file_root_dir).write_yaml(complist) print(f"Components written to '{config_file_root_dir}'")
def run(args): allcomps = MepoState.read_state() max_namelen = len(max([x.name for x in allcomps], key=len)) max_origlen = len( max([version_to_string(x.version) for x in allcomps], key=len)) print_header(max_namelen, max_origlen) for comp in allcomps: git = GitRepository(comp.remote, comp.local) curr_ver = version_to_string(git.get_version()) orig_ver = version_to_string(comp.version) # This command is to try and work with git tag oddities curr_ver = sanitize_version_string(orig_ver, curr_ver, git) print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen)
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() verify.valid_components(args.comp_name, allcomps) comps2pull = [x for x in allcomps if x.name in args.comp_name] for comp in comps2pull: git = GitRepository(comp.remote, comp.local) name, tYpe, is_detached = MepoVersion(*git.get_version()) if is_detached: raise Exception('{} has detached head! Cannot pull.'.format( comp.name)) else: print("Pulling branch %s in %s " % (colors.YELLOW + name + colors.RESET, colors.RESET + comp.name + colors.RESET)) output = git.pull() if not args.quiet: print(output)
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): root_dir = MepoState.get_root_dir() allcomps = MepoState.read_state() if args.comp_name: # single comp name is specified, print relpath if args.comp_name == "_root": # _root is a "hidden" allowed argument for whereis to return # the root dir of the project. Mainly used by mepo-cd print(root_dir) else: verify.valid_components([args.comp_name], allcomps) for comp in allcomps: if comp.name == args.comp_name: full_local_path = os.path.join(root_dir, comp.local) print(_get_relative_path(full_local_path)) else: # print relpaths of all comps max_namelen = len(max([x.name for x in allcomps], key=len)) FMT = '{:<%s.%ss} | {:<s}' % (max_namelen, max_namelen) for comp in allcomps: full_local_path = os.path.join(root_dir, comp.local) print(FMT.format(comp.name, _get_relative_path(full_local_path)))
def run(args): allcomps = MepoState.read_state() comps2crttg = _get_comps_to_list(args.comp_name, allcomps) tf_file = None if args.annotate: create_annotated_tag = True elif args.message: create_annotated_tag = True else: create_annotated_tag = False if create_annotated_tag: # Pop up an editor if a message is not provided if not args.message: EDITOR = git_var('GIT_EDITOR') initial_message = b"" # set up the file # Use delete=False to keep the file around as we send the file name to git commit -F tf = tempfile.NamedTemporaryFile(delete=False) tf_file = tf.name tf.write(initial_message) tf.flush() subprocess.call([EDITOR, tf.name]) for comp in comps2crttg: git = GitRepository(comp.remote, comp.local) git.create_tag(args.tag_name, create_annotated_tag, args.message, tf_file) print('+ {}: {}'.format(comp.name, args.tag_name)) if create_annotated_tag: # Now close and by-hand delete the temp file if not args.message: tf.close() os.unlink(tf.name)
def run(args): allcomps = MepoState.read_state() for comp in allcomps: print(comp.name, end=' ') print()
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)