import copy


def override_repo_refs(repos, override_ref=None, overrides=None):
    """
    Returns a new `repos` dictionary with the CLI overrides applied.
    """
    overrides = overrides or {}
    if not override_ref and not overrides:
        return repos

    repos_copy = copy.deepcopy(repos)
    for repo, repo_data in repos.items():
        if not repo_data:
            continue
        release_data = repo_data.get("openedx-release")
        if not release_data:
            continue
        local_override = overrides.get(str(repo), override_ref)
        if local_override:
            repos_copy[repo]["openedx-release"]["ref"] = local_override

    return repos_copy