diff --git a/setup.py b/setup.py index 9cd6efa7..c6608cb5 100644 --- a/setup.py +++ b/setup.py @@ -82,6 +82,7 @@ "oca-configure-travis= tools.configure_travis:main", "oca-create-branch = tools.create_branch:main", "oca-copier-update = tools.copier_update:main", + "oca-patch-branch = tools.patch_branch:main", ], }, ) diff --git a/tools/patch_branch.py b/tools/patch_branch.py new file mode 100644 index 00000000..dbb86294 --- /dev/null +++ b/tools/patch_branch.py @@ -0,0 +1,35 @@ +"""Apply a patch with git am on a branch in all addons project. +""" +import os +import subprocess + +import click + +from .oca_projects import BranchNotFoundError, get_repositories, temporary_clone + + +@click.command() +@click.argument("branch") +@click.argument("patch-file", type=click.Path(exists=True, dir_okay=False)) +def main(branch, patch_file): + patch_file = os.path.abspath(patch_file) + for repo in get_repositories(): + try: + with temporary_clone(repo, branch): + print("=" * 10, repo, "=" * 10) + # set git user/email + subprocess.check_call( + ["git", "config", "user.name", "oca-git-bot"], + ) + subprocess.check_call( + ["git", "config", "user.email", "oca-git-bot@odoo-community.org"], + ) + # apply patch and commit + r = subprocess.call(["git", "am", patch_file]) + if r != 0: + continue + # subprocess.check_call(["pre-commit", "run", "-a"]) + # subprocess.check_call(["git", "commit", "-am", commit_message]) + subprocess.check_call(["git", "push"]) + except BranchNotFoundError: + pass