Exemple #1
0
def _get_previous_git_tag_from_env_file(repo_path, previous_branch, env_file):
    current_commit = git_utils.get_current_commit(repo_path)

    git_utils.checkout(repo_path, previous_branch)
    previous_tag = _get_git_tag_from_env_file(env_file)

    git_utils.checkout(repo_path, current_commit)

    return previous_tag
Exemple #2
0
def _has_git_tag_changed(repo_path, previous_branch, env_file):
    current_commit = git_utils.get_current_commit(repo_path)

    git_utils.checkout(repo_path, previous_branch)
    previous_tag = _get_git_tag_from_env_file(env_file)

    git_utils.checkout(repo_path, current_commit)
    current_tag = _get_git_tag_from_env_file(env_file)
    return (current_tag is not None) and previous_tag != current_tag
def prepare_hist_repository(hist_repo):
    """Prepare the repository with history data.

    First, the repository is cloned or (if its been cloned already) new content is fetched.
    Additionaly, the repository is checkout to 'master' because we are not sure about its
    previous status.
    Then the log file with all commits is generated.
    """
    git_utils.clone_or_fetch_repository(hist_repo, full_history=True)
    git_utils.checkout(hist_repo, "master")
    git_utils.create_log(hist_repo)
def prepare_hist_repository(hist_repo):
    """Prepare the repository with history data.

    First, the repository is cloned or (if its been cloned already) new content is fetched.
    Additionaly, the repository is checkout to 'master' because we are not sure about its
    previous status.
    Then the log file with all commits is generated.
    """
    git_utils.clone_or_fetch_repository(hist_repo, full_history=True)
    git_utils.checkout(hist_repo, "master")
    git_utils.create_log(hist_repo)
def _create_version_branch(arg_strings=None):
    parser = _make_parser()
    args = parser.parse_args(arg_strings)

    if args.repository:
        repo_name = _get_repo_name(args.repository)
        repo_url = args.repository
        repo_path = os.path.abspath(os.path.join(args.repo_dir, repo_name))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo_name))
        git_utils.clone_repo(repo_url, repo_path)
    elif args.repo_dir:
        repo_path = args.repo_dir
    else:
        repo_path = "./"

    if args.commit:
        git_utils.checkout(repo_path, args.commit)
    current_commit = git_utils.get_current_branch(repo_path)

    git_utils.checkout(repo_path, "HEAD~")
    previous_version = _get_repo_version(repo_path)

    git_utils.checkout(repo_path, current_commit)
    current_version = _get_repo_version(repo_path)

    if args.branch_if_changed and current_version == previous_version:
        print("The version has not changed, no branch created.")
    else:
        if args.branch_if_changed:
            print("The version has changed, creating branch.")
            git_utils.checkout(repo_path, "HEAD~")
            branch_name = "r" + previous_version
        else:
            print("Creating branch.")
            branch_name = "r" + current_version

        if git_utils.branch_exists(repo_path, branch_name):
            print("The branch {} already exists.".format(branch_name))
        else:
            git_utils.create_branch(repo_path, branch_name)
            git_utils.push_branch(repo_path, branch_name)

        if args.branch_if_changed:
            git_utils.checkout(repo_path, current_commit)

    if args.repository:
        shutil.rmtree(repo_path)
Exemple #6
0
def save_git(wd, remote=None, branch=None):
    output = ''
    if (remote):
        output += git.set_remote(git_remote, wd=wd)
    if (branch):
        output += git.checkout(git_branch, wd=wd)
    return output
Exemple #7
0
def save_git(wd, remote=None, branch=None):
    output = ''
    if (remote):
        output += git.set_remote(git_remote, wd=wd)
    if (branch):
        output += git.checkout(git_branch, wd=wd)
    return output
def tag_all_repos(github_org, tag, tag_msg, branch, repo_dir, pat, skipped_repos, prev_tag): # pylint: disable=too-many-arguments
    '''
    Clones, then tags all repos with a given tag, and pushes back to remote.
    These steps are performed in separate loops to make debugging easier.
    '''
    skipped_repos = inputs.parse_arg_list(skipped_repos)
    repos = git_utils.get_all_repos(github_org, pat)
    repos = [repo for repo in repos if repo["name"] not in skipped_repos ]
    print("---------------------------Cloning all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo["name"]))
        git_utils.clone_repo(repo["ssh_url"], repo_path)
        if branch and git_utils.branch_exists(repo_path, branch):
            print("--->Branch '{}' exists, checking it out.".format(branch))
            git_utils.checkout(repo_path, branch)
        elif prev_tag:
            repo_branch = git_utils.get_tag_branch(repo_path, prev_tag)
            print("--->Checking out branch '{}' which contains tag '{}'.".format(repo_branch, prev_tag))
            git_utils.checkout(repo_path, repo_branch)

    print("---------------------------Tagging all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Tagging {}".format(repo["name"]))
        git_utils.create_tag(repo_path, tag, tag_msg)

    push = git_utils.ask_for_input("Would you like to push all tags to remote?")
    if not push.startswith("y"):
        return

    print("---------------------------Pushing all Repos")
    for repo in repos:
        try:
            repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
            print("--->Pushing {}".format(repo["name"]))
            git_utils.push_branch(repo_path, tag)
        except Exception as exc:# pylint: disable=broad-except
            print("Error encountered when trying to push {}".format(repo["name"]))
            print(exc)
            cont_tag = git_utils.ask_for_input("Would you like to continue tagging other repos?")
            if cont_tag.startswith("y"):
                continue
            raise
def read_code_coverage_history(hist_repo, commits, repo_to_measure):
    """Read code coverage history for the selected repository."""
    git_utils.checkout(hist_repo, "master")
    hist_repo = git_utils.update_repository_name(hist_repo)
    filename = get_filename_with_coverage(hist_repo, repo_to_measure)

    code_coverage_history = []

    # checkout to every commit and read the code coverage statistic
    for commit in commits:
        commit_hash = commit[0]
        commit_date = get_commit_date(commit[1])
        git_utils.checkout(hist_repo, commit_hash)
        summary = read_summary(filename)
        if summary is not None:
            summary["date"] = commit_date
            code_coverage_history.append(summary)
    return code_coverage_history
def read_code_coverage_history(hist_repo, commits, repo_to_measure):
    """Read code coverage history for the selected repository."""
    git_utils.checkout(hist_repo, "master")
    hist_repo = git_utils.update_repository_name(hist_repo)
    filename = get_filename_with_coverage(hist_repo, repo_to_measure)

    code_coverage_history = []

    # checkout to every commit and read the code coverage statistic
    for commit in commits:
        commit_hash = commit[0]
        commit_date = history_generator.get_commit_date(commit[1])
        git_utils.checkout(hist_repo, commit_hash)
        summary = read_summary(filename)
        if summary is not None:
            summary["date"] = commit_date
            code_coverage_history.append(summary)

    return code_coverage_history
def read_history(hist_repo, commits, repo_to_measure, summary_postfix, summary_pattern,
                 checks_passed_prefix, checks_passed_pattern,
                 get_filename_function):
    """Read dead code history for the selected repository."""
    git_utils.checkout(hist_repo, "master")
    hist_repo = git_utils.update_repository_name(hist_repo)
    filename = get_filename_function(hist_repo, repo_to_measure)

    history = []

    # checkout to every commit and read the code coverage statistic
    for commit in commits:
        commit_hash = commit[0]
        commit_date = history_generator.get_commit_date(commit[1])
        git_utils.checkout(hist_repo, commit_hash)
        summary = read_summary(filename, summary_postfix, summary_pattern, checks_passed_prefix,
                               checks_passed_pattern)
        if summary is not None:
            summary["date"] = commit_date
            history.append(summary)

    return history
def clone_repos(repos, branch, repo_dir, prev_tag):
    '''
    Clones a list of repos.
    '''
    print("---------------------------Cloning all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo["name"]))
        git_utils.clone_repo(repo["ssh_url"], repo_path)
        if branch and git_utils.branch_exists(repo_path, branch):
            print("--->Branch '{}' exists, checking it out.".format(branch))
            git_utils.checkout(repo_path, branch)
        elif prev_tag:
            repo_branch = git_utils.get_tag_branch(repo_path, prev_tag)
            print("-->Repo branch is: {}".format(repo_branch))
            if git_utils.branch_exists(repo_path,
                                       os.path.basename(repo_branch)):
                print("--->Checking out branch '{}' which contains tag '{}'.".
                      format(repo_branch, prev_tag))
                git_utils.checkout(repo_path, repo_branch)
def read_history(hist_repo, commits, repo_to_measure, summary_postfix, summary_pattern,
                 checks_passed_prefix, checks_passed_pattern,
                 get_filename_function):
    """Read dead code history for the selected repository."""
    git_utils.checkout(hist_repo, "master")
    hist_repo = git_utils.update_repository_name(hist_repo)
    filename = get_filename_function(hist_repo, repo_to_measure)

    history = []

    # checkout to every commit and read the code coverage statistic
    for commit in commits:
        commit_hash = commit[0]
        commit_date = history_generator.get_commit_date(commit[1])
        git_utils.checkout(hist_repo, commit_hash)
        summary = read_summary(filename, summary_postfix, summary_pattern, checks_passed_prefix,
                               checks_passed_pattern)
        if summary is not None:
            summary["date"] = commit_date
            history.append(summary)

    return history
def _do_update(args: argparse.Namespace, updater: Updater,
               metadata: metadata_pb2.MetaData) -> None:
    full_path = updater.project_path

    if args.branch_and_commit:
        git_utils.checkout(full_path, args.remote_name + '/master')
        try:
            git_utils.delete_branch(full_path, TMP_BRANCH_NAME)
        except subprocess.CalledProcessError:
            # Still continue if the branch doesn't exist.
            pass
        git_utils.start_branch(full_path, TMP_BRANCH_NAME)

    updater.update()

    updated_metadata = metadata_pb2.MetaData()
    updated_metadata.CopyFrom(metadata)
    updated_metadata.third_party.version = updater.latest_version
    for metadata_url in updated_metadata.third_party.url:
        if metadata_url == updater.current_url:
            metadata_url.CopyFrom(updater.latest_url)
    # For Rust crates, replace GIT url with ARCHIVE url
    if isinstance(updater, CratesUpdater):
        updater.update_metadata(updated_metadata, full_path)
    fileutils.write_metadata(full_path, updated_metadata, args.keep_date)
    git_utils.add_file(full_path, 'METADATA')

    if args.branch_and_commit:
        msg = 'Upgrade {} to {}\n\nTest: make\n'.format(
            args.path, updater.latest_version)
        git_utils.add_file(full_path, '*')
        git_utils.commit(full_path, msg)

    if args.push_change:
        git_utils.push(full_path, args.remote_name)

    if args.branch_and_commit:
        git_utils.checkout(full_path, args.remote_name + '/master')
Exemple #15
0
def save_git(request, app_id=None):
    
    app = App.objects.get(id=app_id)

    git_remote = request.POST.get('remote')
    git_branch = request.POST.get('branch')

    if not (git_remote and git_branch):
        return HttpResponseServerError("no remote or branch")
    
    out = git.set_remote(git_remote, wd=app.wd)
    print out
    out += git.checkout(git_branch, wd=app.wd)
    print out
    
    return HttpResponse (out)
Exemple #16
0
def save_git(request, app_id=None):

    app = App.objects.get(id=app_id)

    git_remote = request.POST.get('remote')
    git_branch = request.POST.get('branch')

    if not (git_remote and git_branch):
        return HttpResponseServerError("no remote or branch")

    out = git.set_remote(git_remote, wd=app.wd)
    print out
    out += git.checkout(git_branch, wd=app.wd)
    print out

    return HttpResponse(out)
Exemple #17
0
 def on_ok(self):
     git_utils.checkout(self.repo_path,self.checkout_selectone.get_selected_objects())
     self.parentApp.switchFormPrevious()
def _create_version_branch(arg_strings=None):  # pylint: disable=too-many-branches
    parser = _make_parser()
    args = parser.parse_args(arg_strings)

    if args.repository:
        repo_name = _get_repo_name(args.repository)
        repo_url = args.repository
        repo_path = os.path.abspath(os.path.join(args.repo_dir, repo_name))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo_name))
        git_utils.clone_repo(repo_url, repo_path)
    elif args.repo_dir:
        repo_path = args.repo_dir
    else:
        repo_path = "./"

    if args.commit:
        git_utils.checkout(repo_path, args.commit)
    current_commit = git_utils.get_current_branch(repo_path)
    config_file = None
    if args.conda_build_configs:
        config_file = args.conda_build_configs
    try:
        git_utils.checkout(repo_path, "HEAD~")
        previous_version, _ = _get_repo_version(repo_path,
                                                utils.ALL_VARIANTS(),
                                                config_file)

        git_utils.checkout(repo_path, current_commit)
        current_version, _ = _get_repo_version(repo_path, utils.ALL_VARIANTS(),
                                               config_file)

        if args.branch_if_changed and _versions_match(current_version,
                                                      previous_version):
            print("The version has not changed, no branch created.")
        else:
            if args.branch_if_changed:
                print("The version has changed, creating branch.")
                git_utils.checkout(repo_path, "HEAD~")
                branch_name = "r" + previous_version
            else:
                print("Creating branch.")
                branch_name = "r" + current_version

            if git_utils.branch_exists(repo_path, branch_name):
                print("The branch {} already exists.".format(branch_name))
            else:
                git_utils.create_branch(repo_path, branch_name)
                git_utils.push_branch(repo_path, branch_name)

            if args.branch_if_changed:
                git_utils.checkout(repo_path, current_commit)

        if args.repository:
            shutil.rmtree(repo_path)
    except Exception as exc:  # pylint: disable=broad-except
        if args.branch_if_changed:
            git_utils.checkout(repo_path, current_commit)
        raise exc