<commit_before>"""Create a branch in all addons project.

TODO
- load copier answers from a previous branch
"""
import subprocess

import click

from .oca_projects import get_repositories, temporary_clone


@click.command("Create an orphan branch from a 'copier' template")
@click.argument("new_branch")
@click.option(
    "--copier-template",
    default="gh:oca/oca-addons-repo-template",
    show_default=True,
)
@click.option(
    "--copier-template-vcs-ref",
)
def main(new_branch, copier_template, copier_template_vcs_ref):
    for repo in get_repositories():
        print("=" * 10, repo, "=" * 10)
        with temporary_clone(repo):
            # check if branch already exists
            if subprocess.check_output(
                ["git", "ls-remote", "--head", "origin", new_branch]
            ):
                print(f"branch {new_branch} already exist in {repo}")
                continue
            # set git user/email
            subprocess.check_call(
                ["git", "config", "user.name", "oca-git-bot"],
            )
            subprocess.check_call(
                ["git", "config", "user.email", "<EMAIL>"],
            )
            # create empty git branch
            subprocess.check_call(["git", "checkout", "--orphan", new_branch])
            subprocess.check_call(["git", "reset", "--hard"])
            # copier
            copier_cmd = [
                "copier",
                "--data",
                f"odoo_version={new_branch}",
                "--data",
                f"repo_slug={repo}",
                "--data",
                f"repo_name={repo}",
                "--data",
                "dependency_installation_mode=PIP",
                "--force",
            ]
            if copier_template_vcs_ref:
                copier_cmd += ["--vcs-ref", copier_template_vcs_ref]
            copier_cmd += [copier_template, "."]
            subprocess.check_call(copier_cmd)
            # pre-commit run -a
            subprocess.check_call(["git", "add", "."])
            subprocess.call(["pre-commit", "run", "-a"])
            # commit and push
            subprocess.check_call(["git", "add", "."])
            subprocess.check_call(
                ["git", "commit", "-m", f"Initialize {new_branch} branch"]
            )
            subprocess.check_call(["git", "push", "origin", new_branch])<commit_msg>create-branch: double check pre-commit<commit_after>"""Create a branch in all addons project.

TODO
- load copier answers from a previous branch
"""
import subprocess

import click

from .oca_projects import get_repositories, temporary_clone


@click.command("Create an orphan branch from a 'copier' template")
@click.argument("new_branch")
@click.option(
    "--copier-template",
    default="gh:oca/oca-addons-repo-template",
    show_default=True,
)
@click.option(
    "--copier-template-vcs-ref",
)
def main(new_branch, copier_template, copier_template_vcs_ref):
    for repo in get_repositories():
        print("=" * 10, repo, "=" * 10)
        with temporary_clone(repo):
            # check if branch already exists
            if subprocess.check_output(
                ["git", "ls-remote", "--head", "origin", new_branch]
            ):
                print(f"branch {new_branch} already exist in {repo}")
                continue
            # set git user/email
            subprocess.check_call(
                ["git", "config", "user.name", "oca-git-bot"],
            )
            subprocess.check_call(
                ["git", "config", "user.email", "<EMAIL>"],
            )
            # create empty git branch
            subprocess.check_call(["git", "checkout", "--orphan", new_branch])
            subprocess.check_call(["git", "reset", "--hard"])
            # copier
            copier_cmd = [
                "copier",
                "--data",
                f"odoo_version={new_branch}",
                "--data",
                f"repo_slug={repo}",
                "--data",
                f"repo_name={repo}",
                "--data",
                "dependency_installation_mode=PIP",
                "--force",
            ]
            if copier_template_vcs_ref:
                copier_cmd += ["--vcs-ref", copier_template_vcs_ref]
            copier_cmd += [copier_template, "."]
            subprocess.check_call(copier_cmd)
            # pre-commit run -a
            subprocess.check_call(["git", "add", "."])
            subprocess.call(["pre-commit", "run", "-a"])
            # commit and push
            subprocess.check_call(["git", "add", "."])
            subprocess.check_call(
                ["git", "commit", "-m", f"Initialize {new_branch} branch"]
            )
            subprocess.check_call(["pre-commit", "run", "-a"])  # to be sure
            subprocess.check_call(["git", "push", "origin", new_branch])
{'fraction_non_alphanumeric': 0.14554087530966145, 'fraction_numerical': 0.0016515276630883566, 'mean_word_length': 1.8349912229373904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589025', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1375, 'n_words': 288}