Skip to content

fix: skip base-branch merge in worktree for cherry-pick operations#1062

Open
rnetser wants to merge 1 commit intomainfrom
fix/cherry-pick-skip-base-merge
Open

fix: skip base-branch merge in worktree for cherry-pick operations#1062
rnetser wants to merge 1 commit intomainfrom
fix/cherry-pick-skip-base-merge

Conversation

@rnetser
Copy link
Copy Markdown
Collaborator

@rnetser rnetser commented Apr 5, 2026

Summary

  • _checkout_worktree() merges origin/{base_branch} into the PR branch for PR testing purposes
  • When called from cherry_pick(), this merge is unnecessary — cherry-pick has its own setup commands that checkout the target branch
  • If the PR has conflicts with main (e.g., needs-rebase), this merge fails and aborts the cherry-pick before it even starts
  • Fix adds skip_merge=True parameter to skip the merge step for cherry-pick operations

Bug Details

Reported on RedHatQE/openshift-virtualization-tests#3455: /cherry-pick cnv-4.20 failed silently (no PR comment posted) because _checkout_worktree() tried to merge origin/main into the PR branch, which had conflicts.

The bug was latent since commit 8c7bd27 (2025-11-13, "perf(git): replace multiple clones with single clone + worktrees"). It only manifests when cherry-picking a PR that has conflicts with its base branch — otherwise the merge succeeds harmlessly and is immediately discarded by cherry-pick's own setup commands.

Test plan

  • Added test verifying skip_merge=True prevents merge command execution
  • Added test verifying cherry_pick() passes skip_merge=True to _checkout_worktree()
  • All 1493 tests pass
  • 90.64% coverage (meets 90% threshold)

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Cherry-pick operations now skip merging the PR base branch into the working tree.
  • Tests

    • Added tests for skip-merge functionality in worktree operations.

Add skip_merge parameter to _checkout_worktree() and pass skip_merge=True
when called from cherry_pick(). The default merge of origin/main into the
worktree is unnecessary for cherry-picks (which manage their own branch
setup) and breaks when the PR has conflicts with main.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 826d0438-0662-4adc-b18c-3ddc7b214345

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3f773 and 7755f8b.

📒 Files selected for processing (2)
  • webhook_server/libs/handlers/runner_handler.py
  • webhook_server/tests/test_runner_handler.py

Walkthrough

The pull request adds a skip_merge parameter to the _checkout_worktree method that conditionally disables merging the PR base branch into the worktree. The cherry_pick method is updated to call this method with skip_merge=True, preventing implicit base branch merges during cherry-pick operations. Test coverage is added to verify the new behavior.

Changes

Cohort / File(s) Summary
Core Logic Update
webhook_server/libs/handlers/runner_handler.py
Added skip_merge: bool = False parameter to _checkout_worktree() method; merge operation now conditionally executes only when skip_merge is False. Updated cherry_pick() to invoke _checkout_worktree(..., skip_merge=True) to disable base branch merging for cherry-pick workflows.
Test Coverage
webhook_server/tests/test_runner_handler.py
Added test_checkout_worktree_skip_merge to verify that merge commands are never invoked when skip_merge=True. Added test_cherry_pick_calls_checkout_worktree_with_skip_merge to assert that cherry_pick() propagates skip_merge=True to the underlying _checkout_worktree() call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #1042: Modifies cherry-pick continuation logic (CHERRY_PICK_HEAD handling) in the same cherry-pick workflow method that this PR updates with the skip_merge parameter.
  • #909: Updates _checkout_worktree() method in RunnerHandler with an optimization to reuse the main clone when the target branch is already checked out, directly intersecting with this PR's changes to the same method.
  • #1046: Modifies cherry-pick conflict-resolution and empty-commit handling in RunnerHandler.cherry_pick, operating within the same cherry-pick workflow being refactored by this PR's skip_merge logic.

Suggested labels

size/M, branch-main

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: skip base-branch merge in worktree for cherry-pick operations' accurately and concisely describes the main change: adding a skip_merge parameter to prevent unnecessary base-branch merging in cherry-pick workflows.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cherry-pick-skip-base-merge

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@myakove-bot
Copy link
Copy Markdown
Collaborator

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest python-module-install - Test Python package installation
  • /retest pre-commit - Run pre-commit hooks and checks
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 1 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  5. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge
AI Features
  • Conventional Title: Mode: fix (claude/claude-opus-4-6[1m])
  • Cherry-Pick Conflict Resolution: Enabled (claude/claude-opus-4-6[1m])
  • Test Oracle: Triggers: approved (claude/claude-opus-4-6[1m]); /test-oracle can be used anytime

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is removed on new commits unless the push is detected as a clean rebase
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@rnetser
Copy link
Copy Markdown
Collaborator Author

rnetser commented Apr 5, 2026

/build-and-push-container

@myakove-bot
Copy link
Copy Markdown
Collaborator

New container for ghcr.io/myk-org/github-webhook-server:pr-1062 published

@rnetser
Copy link
Copy Markdown
Collaborator Author

rnetser commented Apr 5, 2026

/verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants