Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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}')
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
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))
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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))
Exemplo n.º 11
0
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))
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
def check_component_status(comp):
    git = GitRepository(comp.remote, comp.local)

    # version_to_string can strip off 'origin/' for display purposes
    # so we save the "internal" name for comparison
    internal_state_branch_name = git.get_version()[0]

    # This can return non "origin/" names for detached head branches
    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)

    return (curr_ver, internal_state_branch_name, git.check_status())
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
def _update_comp(comp):
    git = GitRepository(comp.remote, comp.local)
    orig_ver = comp.version
    curr_ver = MepoVersion(*git.get_version())

    orig_ver_is_tag_or_hash = (orig_ver.type == 't' or orig_ver.type == 'h')
    curr_ver_is_tag_or_hash = (curr_ver.type == 't' or curr_ver.type == 'h')

    if orig_ver_is_tag_or_hash and curr_ver_is_tag_or_hash:
        # This command is to try and work with git tag oddities
        curr_ver_to_use = sanitize_version_string(orig_ver.name, curr_ver.name,
                                                  git)
        if curr_ver_to_use == orig_ver.name:
            comp.version = orig_ver
        else:
            _verify_local_and_remote_commit_ids_match(git, curr_ver_to_use,
                                                      comp.name, curr_ver.type)
            comp.version = curr_ver
    else:
        if _version_has_changed(curr_ver, orig_ver, comp.name):
            _verify_local_and_remote_commit_ids_match(git, curr_ver.name,
                                                      comp.name, curr_ver.type)
            comp.version = curr_ver
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
def check_component_status(comp):
    git = GitRepository(comp.remote, comp.local)
    curr_ver = version_to_string(git.get_version())
    return (curr_ver, git.check_status())
Exemplo n.º 23
0
def check_component_diff(comp, args):
    git = GitRepository(comp.remote, comp.local)
    return git.run_diff(args)
Exemplo n.º 24
0
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)