Skip to content

feat: add smart_rebase algorithm for merged commit handling#1098

Closed
jd wants to merge 1 commit intomainfrom
devs/jd/feat/pre-push-hook-intercept/I74e9b3acbc71ea6eb3cc343c137174a68b20a254
Closed

feat: add smart_rebase algorithm for merged commit handling#1098
jd wants to merge 1 commit intomainfrom
devs/jd/feat/pre-push-hook-intercept/I74e9b3acbc71ea6eb3cc343c137174a68b20a254

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented Apr 9, 2026

Adds smart_rebase() that detects merged PRs via the GitHub API and
handles them during rebase. If merged commits are found, it does a
single git rebase -i that both drops them and rebases onto trunk,
avoiding conflicts from PRs modified on GitHub before merge.

If no commits are merged, falls back to simple git pull --rebase.

Integrated into mergify stack push during its rebase step.

Copilot AI review requested due to automatic review settings April 9, 2026 14:39
@mergify mergify bot had a problem deploying to Mergify Merge Protections April 9, 2026 14:39 Failure
@jd
Copy link
Copy Markdown
Member Author

jd commented Apr 9, 2026

This pull request is part of a stack:

  1. feat: add smart_rebase algorithm for merged commit handling (#1098) 👈
  2. feat: add mergify stack sync CLI command (#1099)
  3. feat: add inline CI, review, and merge status to mergify stack list (#1100)
  4. style: use compact Unicode symbols instead of emoji in CLI output (#1101)

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 🤖 Continuous Integration

This rule is failing.
  • all of:
    • check-success=ci-gate

🔴 👀 Review Requirements

This rule is failing.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🔴 🔎 Reviews

This rule is failing.
  • #review-requested = 0
  • #review-threads-unresolved = 0
  • #changes-requested-reviews-by = 0

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?:

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

@mergify mergify bot requested a review from a team April 9, 2026 14:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new stack sync/rebase flow that queries GitHub to detect already-merged stack commits and, when present, performs a single interactive rebase that drops those commits while rebasing onto trunk. This is wired into mergify stack push and covered by a new test suite for sync status detection and the smart_rebase() decision logic.

Changes:

  • Introduce mergify_cli/stack/sync.py with get_sync_status(), _write_drop_script(), and smart_rebase().
  • Update mergify stack push rebase step to use smart_rebase() and log how many merged commits were dropped.
  • Add comprehensive tests covering merged vs remaining commit classification and smart_rebase() behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
mergify_cli/stack/sync.py Implements merged-commit detection via GitHub API and a drop-on-rebase mechanism using GIT_SEQUENCE_EDITOR.
mergify_cli/stack/push.py Switches push-time rebase logic from git pull --rebase to smart_rebase().
mergify_cli/tests/stack/test_sync.py Adds unit tests for sync status detection, drop script behavior, and smart_rebase() decision paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return status


async def stack_sync(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used in this PR.

Adds smart_rebase() that detects merged PRs via the GitHub API and
handles them during rebase. If merged commits are found, it does a
single `git rebase -i` that both drops them and rebases onto trunk,
avoiding conflicts from PRs modified on GitHub before merge.

If no commits are merged, falls back to simple `git pull --rebase`.

Integrated into `mergify stack push` during its rebase step.

Change-Id: I74e9b3acbc71ea6eb3cc343c137174a68b20a254
Claude-Session-Id: 2d9f4a52-4a1d-4a50-a459-3b57847dec9f
@jd jd force-pushed the devs/jd/feat/pre-push-hook-intercept/I74e9b3acbc71ea6eb3cc343c137174a68b20a254 branch from 6cbd57b to 7a61561 Compare April 9, 2026 15:04
@mergify mergify bot had a problem deploying to Mergify Merge Protections April 9, 2026 15:04 Failure
@jd jd closed this Apr 10, 2026
@jd jd deleted the devs/jd/feat/pre-push-hook-intercept/I74e9b3acbc71ea6eb3cc343c137174a68b20a254 branch April 10, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants