Skip to content

Commit 38b1e80

Browse files
ivantodorovichgurneyalex
authored andcommitted
[IMP] Implement otools-submodule push: ported from invoke submodule.push
1 parent 0b65570 commit 38b1e80

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

changes.d/+56a73459.feat.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement otools-submodule push (ported invoke submodule.push)

odoo_tools/cli/submodule.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,21 @@ def sync_remote(submodule_path=None, repo=None, force_remote=False):
130130
git.checkout(branch_name=odoo_version)
131131

132132

133+
@cli.command()
134+
@click.argument("submodule_path")
135+
@click.option(
136+
"--target-branch",
137+
default=None,
138+
help="Target branch name. If omitted, computed automatically.",
139+
)
140+
def push(submodule_path, target_branch=None):
141+
"""Push the current state of a submodule to the company remote."""
142+
repo = pm_utils.Repo(submodule_path)
143+
target_branch = target_branch or pm_utils.gh.get_target_branch()
144+
ui.echo(f"Pushing {repo.name} to {repo.company_git_remote}/{target_branch}")
145+
repo.push_to_remote(target_branch=target_branch)
146+
ui.echo("Done.")
147+
148+
133149
if __name__ == "__main__":
134150
cli()

odoo_tools/utils/pending_merge.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@ def _handle_empty_merges_file(self, delete_file=False):
602602
):
603603
self.abs_merges_path.unlink()
604604

605+
def push_to_remote(self, target_branch=None):
606+
target_branch = target_branch or gh.get_target_branch()
607+
aggregator = self.get_aggregator(target_branch=target_branch)
608+
with cd(self.abs_path):
609+
aggregator._switch_to_branch(target_branch)
610+
aggregator.push()
611+
605612
def rebuild_consolidation_branch(self, push=False):
606613
aggregator = self.get_aggregator()
607614
aggregator.aggregate()

tests/test_submodule.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from odoo_tools.cli import submodule
77

8-
from .common import get_fixture_path, mock_subprocess_run
8+
from .common import get_fixture_path, mock_pending_merge_repo_paths, mock_subprocess_run
99

1010

1111
@pytest.mark.project_setup(
@@ -152,6 +152,26 @@ def test_ls(project):
152152
]
153153

154154

155+
@pytest.mark.project_setup(
156+
manifest=dict(odoo_version="16.0"),
157+
proj_version="16.0.1.2.3",
158+
)
159+
def test_push(project):
160+
mock_pending_merge_repo_paths("some-repo", src=True, pending=True)
161+
with mock.patch.object(
162+
submodule.pm_utils.Repo, "push_to_remote"
163+
) as mock_push_to_remote:
164+
result = project.invoke(
165+
submodule.push,
166+
["some-repo", "--target-branch", "my-target-branch"],
167+
catch_exceptions=False,
168+
)
169+
assert result.exit_code == 0
170+
mock_push_to_remote.assert_called_once_with(target_branch="my-target-branch")
171+
assert "my-target-branch" in result.output
172+
assert "Done." in result.output
173+
174+
155175
@pytest.mark.project_setup(
156176
manifest=dict(odoo_version="16.0"),
157177
proj_version="16.0.1.2.3",

0 commit comments

Comments
 (0)