From: Patrick Donnelly Date: Mon, 13 Jul 2026 18:24:26 +0000 (-0400) Subject: script/ptl-tool: handle cherry-pick conflicts on branch-specific commits X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eef55dbb754387711ef846285d2877435e7d1819;p=ceph.git script/ptl-tool: handle cherry-pick conflicts on branch-specific commits Previously, ConflictSimulationCheck only anticipated merge conflicts when simulating upstream cherry-picks. If a branch-specific commit (such as test repo branch adjustments or backport metadata changes) failed to apply cleanly to the target base branch, the script threw an unhandled GitCommandError and crashed with an unhandled traceback. Wrap branch-specific commit cherry-picks in a try...except block. When a conflict occurs, abort the cherry-pick, record a "Rebase Required" simulation failure in the audit report, and either prompt the user in interactive mode or gracefully halt check execution in CI mode. Signed-off-by: Patrick Donnelly --- diff --git a/src/script/ptl-tool.py b/src/script/ptl-tool.py index e839bd0ee99..a602c025997 100755 --- a/src/script/ptl-tool.py +++ b/src/script/ptl-tool.py @@ -1341,7 +1341,36 @@ class ConflictSimulationCheck(BaseAuditCheck): continue else: log.info(f"Applying branch-specific commit {commit.hexsha[:8]} ...") - wt_repo.git(c=SANDBOX_CFG).cherry_pick("--allow-empty", commit.hexsha) + try: + wt_repo.git(c=SANDBOX_CFG).cherry_pick("--allow-empty", commit.hexsha) + except git.exc.GitCommandError: + log.error(f"Failed to apply branch-specific commit {commit.hexsha[:8]}! The PR likely has conflicts with the base branch and needs a rebase.") + wt_repo.git.cherry_pick('--abort') + + if args.ci_mode: + md_text = f"### Automated PR Review - Rebase Required\n\nBranch-specific commit `{commit.hexsha[:8]}` failed to apply cleanly to the base branch during simulation. The PR likely has conflicts and needs a rebase." + report.add("Simulation Failure", md_text) + raise SkipToMerge() + + while True: + ans = input("How do you want to handle this? [p/m/r/o/q] (p=proceed simulation anyway, m=skip to merge, r=add to review and skip simulation, o=open PR in browser, q=quit) ").strip().lower() + if ans == 'o': + url = f"https://github.com/{BASE_PROJECT}/{BASE_REPO}/pull/{pr}" + open_in_browser([url]) + print(f"Opened {url} in browser.") + elif ans == 'm': + raise SkipToMerge() + elif ans == 'r': + md_text = f"### Automated PR Review - Rebase Required\n\nBranch-specific commit `{commit.hexsha[:8]}` failed to apply cleanly to the base branch during simulation. The PR likely has conflicts and needs a rebase." + report.add("Simulation Failure", md_text) + report.record_failure() + raise SkipToMerge() + elif ans == 'q': + sys.exit(1) + elif ans == 'p': + break + else: + print("Invalid choice. Please enter p, m, r, o, or q.") if recorded_deviations: md_text = """