def switch_to_temp_branch(repo: BlueprintRepo, defined_branch_in_file: str): stashed_flag = False created_remote_flag = False created_local_temp_branch = False random_suffix = "".join( random.choice(string.ascii_lowercase) for i in range(10)) uncommitted_branch_name = UNCOMMITTED_BRANCH_NAME + defined_branch_in_file + "-" + random_suffix stashed_items_before = count_stashed_items(repo) try: if repo.is_dirty() or repo.untracked_files: create_gitkeep_in_branch() stash_local_changes(repo) stashed_flag = True created_local_temp_branch = create_local_temp_branch( repo, uncommitted_branch_name) if stashed_flag: preserve_uncommitted_code(repo) commit_to_local_temp_branch(repo) create_remote_branch(repo, uncommitted_branch_name) created_remote_flag = True except Exception as e: logger.debug(f"An issue while creating temp branch: {str(e)}") if not stashed_flag and (count_stashed_items(repo) > stashed_items_before): revert_from_uncommitted_code(repo) if created_local_temp_branch: revert_from_local_temp_branch(repo, defined_branch_in_file, stashed_flag) delete_temp_local_branch(repo, defined_branch_in_file) if created_remote_flag: delete_temp_remote_branch(repo, defined_branch_in_file) raise return uncommitted_branch_name
def debug_output_about_repo_examination(repo: BlueprintRepo, blueprint_name: str): if not repo.repo_has_blueprint(blueprint_name): logger.debug( f"Current repo does not contain a definition for the blueprint '{blueprint_name}'." ) if repo.is_dirty(): logger.debug("You have uncommitted changes") if repo.untracked_files: logger.debug( "Untracked files detected - only staged or committed files will be used when testing local changes" ) if not repo.current_branch_exists_on_remote(): logger.debug("Your current local branch doesn't exist on remote") # raise BadBlueprintRepo("Your current local branch doesn't exist on remote") if not repo.is_current_branch_synced(): logger.debug("Your local branch is not synced with remote")
def examine_blueprint_working_branch(repo: BlueprintRepo, blueprint_name: str) -> None: if repo.is_repo_detached(): raise BadBlueprintRepo("Repo's HEAD is in detached state") if not repo.repo_has_blueprint(blueprint_name): logger.debug(f"Current repo does not contain a definition for the blueprint '{blueprint_name}'.") if repo.is_dirty(): logger.debug("You have uncommitted changes") if repo.untracked_files: logger.debug( "Untracked files detected - only staged or committed files will be used when testing local changes" ) if not repo.current_branch_exists_on_remote(): logger.debug("Your current local branch doesn't exist on remote") # raise BadBlueprintRepo("Your current local branch doesn't exist on remote") if not repo.is_current_branch_synced(): logger.debug("Your local branch is not synced with remote") return