def manage_git_folder(gh_token, temp_dir, git_id, *, pr_number=None):
    """Context manager to avoid readonly problem while cleanup the temp dir.

    If PR number is given, use magic branches "pull" from Github.
    """
    _LOGGER.debug("Git ID %s", git_id)
    if Path(git_id).exists():
        yield git_id
        return  # Do not erase a local folder, just skip here

    # Clone the specific branch
    split_git_id = git_id.split("@")
    branch = split_git_id[1] if len(split_git_id) > 1 else None
    clone_to_path(gh_token, temp_dir, split_git_id[0], branch_or_commit=branch, pr_number=pr_number)
    try:
        yield temp_dir
        # Pre-cleanup for Windows http://bugs.python.org/issue26660
    finally:
        _LOGGER.debug("Preclean Rest folder")
        shutil.rmtree(temp_dir, onerror=remove_readonly)
def manage_git_folder ( gh_token , temp_dir , git_id , * , pr_number = None ) : _LOGGER . debug ( "Git ID %s" , git_id ) if Path ( git_id ) . exists ( ) : yield git_id return split_git_id = git_id . split ( "@" ) branch = split_git_id [ 1 ] if len ( split_git_id ) > 1 else None clone_to_path ( gh_token , temp_dir , split_git_id [ 0 ] , branch_or_commit = branch , pr_number = pr_number ) try : yield temp_dir finally : _LOGGER . debug ( "Preclean Rest folder" ) shutil . rmtree ( temp_dir , onerror = remove_readonly )
Context manager to avoid readonly problem while cleanup the temp dir.

    If PR number is given, use magic branches "pull" from Github.