Skip to content

Commit 85ad957

Browse files
[FIX] otools-pending remove: crash when removing last pending merge
When the last pending PR was removed, the merges file was deleted but the aggregator still tried to read it, causing a ConfigException. Skip aggregation when the file has been removed (no merges left).
1 parent 0b65570 commit 85ad957

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

odoo_tools/utils/pending_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def remove_pending(entity_url, aggregate=True):
687687

688688
if not pending_merges_present and not patches:
689689
repo.abs_merges_path.unlink()
690-
if aggregate:
690+
elif aggregate:
691691
aggregator = repo.get_aggregator()
692692
aggregator.aggregate()
693693
return repo

tests/test_utils_pending_merge.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,36 @@ def test_remove_pending_pr():
260260
assert merges == expected
261261

262262

263+
@pytest.mark.usefixtures("all_template_versions")
264+
def test_remove_pending_last_pr():
265+
"""Test removing the last pending PR deletes the merges file."""
266+
name = "edi"
267+
# Template with only one pending PR (besides the base branch)
268+
tmpl = """
269+
../{ext_src_rel_path}/{repo_name}:
270+
remotes:
271+
camptocamp: git@github.com:camptocamp/{repo_name}.git
272+
{org_name}: git@github.com:{org_name}/{repo_name}.git
273+
target: camptocamp merge-branch-{pid}-master
274+
merges:
275+
- {org_name} 14.0
276+
- {org_name} refs/pull/774/head
277+
"""
278+
mock_pending_merge_repo_paths(name, tmpl=tmpl)
279+
repo = Repo(name, path_check=False)
280+
merges = repo.merges_config().get("merges", [])
281+
assert merges == ["OCA 14.0", "OCA refs/pull/774/head"]
282+
# Remove the only pending PR via the top-level function
283+
# (which deletes the file when no PRs are left)
284+
# Use aggregate=True (the default) to reproduce the bug
285+
pm_utils.remove_pending(
286+
"https://github.com/OCA/edi/pull/774",
287+
aggregate=True,
288+
)
289+
# The merges file should have been removed
290+
assert not repo.abs_merges_path.exists()
291+
292+
263293
# TODO: test all cases
264294
def __test_add_pending_commit_from_scratch():
265295
name = "edi"

0 commit comments

Comments
 (0)