Skip to content

Commit 4b3d3eb

Browse files
ivantodorovichgurneyalex
authored andcommitted
[FIX] otools-pending add: update .gitmodules when adding first pending merge
When adding the first pending merge to a submodule, the consolidated branch is created on the company fork (e.g. camptocamp), but .gitmodules was not updated to reflect this. This caused .gitmodules to still point to the original upstream (e.g. OCA) instead of the company fork.
1 parent 06dadda commit 4b3d3eb

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

changes.d/+600c7378.fix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
otools-pending add: update .gitmodules when adding first pending merge

odoo_tools/utils/pending_merge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def generate_pending_merges_file_template(self, upstream):
178178

179179
config.insert(2, "merges", CommentedSeq([base_merge]))
180180
self.update_merges_config(config)
181+
git.submodule_set_url(self.path, remote_company_url)
181182

182183
def update_pending_merges_file_base_merge(self, skip_questions: bool = False):
183184
"""Checks that the base merge for an odoo/enterprise repository us up-to-date"""

tests/test_utils_pending_merge.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from unittest import mock
66

77
import pytest
8+
from git.config import GitConfigParser
89

910
from odoo_tools.exceptions import Exit, PathNotFound
1011
from odoo_tools.utils import pending_merge as pm_utils
@@ -110,6 +111,14 @@ def test_add_pending_pr_from_scratch():
110111
repo_name = "edi-framework"
111112
mock_pending_merge_repo_paths(repo_name, pending=False)
112113
repo = Repo(repo_name, path_check=False)
114+
# Setup .gitmodules pointing to the upstream (OCA)
115+
with Path(".gitmodules").open("w") as f:
116+
f.write(
117+
f'[submodule "{repo.path}"]\n'
118+
f"\tpath = {repo.path}\n"
119+
f"\turl = git@github.com:OCA/{repo_name}.git\n"
120+
f"\tbranch = 16.0\n"
121+
)
113122
repo.generate_pending_merges_file_template("OCA")
114123
repo.add_pending_pull_request("OCA", 778)
115124
expected = {
@@ -121,6 +130,10 @@ def test_add_pending_pr_from_scratch():
121130
"target": "camptocamp merge-branch-1234-master",
122131
}
123132
compare_dict(repo.merges_config(), expected)
133+
# .gitmodules should now point to the company fork
134+
config = GitConfigParser(".gitmodules", read_only=True)
135+
url = config.get(f'submodule "{repo.path}"', "url")
136+
assert url == f"git@github.com:camptocamp/{repo_name}.git"
124137

125138

126139
# TODO: test all cases
@@ -152,6 +165,14 @@ def test_add_pending_pr():
152165
@pytest.mark.project_setup(proj_tmpl_ver=1)
153166
def test_add_pending_odoo_pr_v1():
154167
repo = Repo("odoo", path_check=False)
168+
# Setup .gitmodules pointing to the upstream (odoo)
169+
with Path(".gitmodules").open("w") as f:
170+
f.write(
171+
f'[submodule "{repo.path}"]\n'
172+
f"\tpath = {repo.path}\n"
173+
f"\turl = git@github.com:odoo/odoo.git\n"
174+
f"\tbranch = 14.0\n"
175+
)
155176
# 1: start with no pending merges, generate the pending merges file
156177
assert not repo.has_pending_merges()
157178
with mock.patch("odoo_tools.utils.ui.ask_confirmation", return_value=True):
@@ -170,6 +191,10 @@ def test_add_pending_odoo_pr_v1():
170191
"target": "camptocamp merge-branch-1234-master",
171192
},
172193
)
194+
# .gitmodules should now point to the company fork
195+
config = GitConfigParser(".gitmodules", read_only=True)
196+
url = config.get(f'submodule "{repo.path}"', "url")
197+
assert url == "git@github.com:camptocamp/odoo.git"
173198
# 2: add a pending merge
174199
with mock.patch("odoo_tools.utils.ui.ask_confirmation", return_value=True):
175200
repo.add_pending_pull_request("odoo", 778)

0 commit comments

Comments
 (0)