Skip to content

Commit 25ed07b

Browse files
[FIX] otools-pending remove: crash when removing last pending merge
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0b65570 commit 25ed07b

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

odoo_tools/utils/gh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def get_current_rebase_branch():
5959
# directories, in a file named "head-name"
6060
rebase_dir = run(f"git rev-parse --git-path {rebase_file}")
6161
rebase_dir = Path(rebase_dir)
62-
if rebase_dir.exists():
62+
rebase_head_name = rebase_dir / "head-name"
63+
if rebase_head_name.exists():
6364
head_name = (rebase_dir / "head-name").read_text().strip()
6465
current_branch = head_name.replace("refs/heads/", "")
6566
break

odoo_tools/utils/pending_merge.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -679,15 +679,9 @@ def remove_pending(entity_url, aggregate=True):
679679

680680
# check if that file is useless since it has an empty `merges` section
681681
# if it does - drop it instead of writing a new file version
682-
# only the upstream branch is present in `merges`
683-
# first item is `- oca 11.0` or similar
684-
config = repo.merges_config()
685-
pending_merges_present = len(config["merges"]) > 1
686-
patches = len(config.get("shell_command_after", {}))
687-
688-
if not pending_merges_present and not patches:
689-
repo.abs_merges_path.unlink()
690-
if aggregate:
682+
if not repo.has_any_pr_left():
683+
repo._handle_empty_merges_file(delete_file=True)
684+
elif aggregate:
691685
aggregator = repo.get_aggregator()
692686
aggregator.aggregate()
693687
return repo

tests/test_utils_pending_merge.py

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

262262

263+
@pytest.mark.usefixtures("all_template_versions")
264+
@pytest.mark.project_setup(
265+
manifest=dict(odoo_version="14.0"), proj_version="14.0.0.1.0"
266+
)
267+
def test_remove_pending_last_pr():
268+
"""Test removing the last pending PR deletes the merges file."""
269+
name = "edi"
270+
# Template with only one pending PR (besides the base branch)
271+
tmpl = """
272+
../{ext_src_rel_path}/{repo_name}:
273+
remotes:
274+
camptocamp: git@github.com:camptocamp/{repo_name}.git
275+
{org_name}: git@github.com:{org_name}/{repo_name}.git
276+
target: camptocamp merge-branch-{pid}-master
277+
merges:
278+
- {org_name} 14.0
279+
- {org_name} refs/pull/774/head
280+
"""
281+
mock_pending_merge_repo_paths(name, tmpl=tmpl)
282+
repo = Repo(name, path_check=False)
283+
merges = repo.merges_config().get("merges", [])
284+
assert merges == ["OCA 14.0", "OCA refs/pull/774/head"]
285+
# Remove the only pending PR via the top-level function
286+
with mock.patch.object(Repo, "_handle_empty_merges_file") as mock_handle:
287+
pm_utils.remove_pending("https://github.com/OCA/edi/pull/774")
288+
mock_handle.assert_called_once()
289+
290+
263291
# TODO: test all cases
264292
def __test_add_pending_commit_from_scratch():
265293
name = "edi"

0 commit comments

Comments
 (0)