Skip to content

fix(stack): anchor old PR head SHAs in local refs for revision history#1314

Closed
jd wants to merge 1 commit into
mainfrom
devs/jd/fix/stack-revision-history-fetch-resilience/anchor-old-pr-head-shas-local-refs-revision--e5aebff2
Closed

fix(stack): anchor old PR head SHAs in local refs for revision history#1314
jd wants to merge 1 commit into
mainfrom
devs/jd/fix/stack-revision-history-fetch-resilience/anchor-old-pr-head-shas-local-refs-revision--e5aebff2

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented Apr 29, 2026

fetch_old_pr_heads previously fetched refs/pull/N/head with no
destination refspec, leaving the SHA reachable only via FETCH_HEAD —
which any subsequent fetch (or background gc) can drop. When the
SHA is no longer locally reachable, git show <old_sha> fails inside
_git_patch_id, and detect_change_type falls back to the
"unknown" classification in the PR's revision-history comment.

Fetch into a stable per-PR ref under refs/mergify/stack/old-pr-heads/<N>
(forced refspec, with --no-write-fetch-head to avoid touching the
shared FETCH_HEAD pointer). The SHA is then anchored by a real ref
for the lifetime of the patch-id comparison and beyond, so future
runs can compare even after a long gap.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

`fetch_old_pr_heads` previously fetched `refs/pull/N/head` with no
destination refspec, leaving the SHA reachable only via FETCH_HEAD —
which any subsequent fetch (or background `gc`) can drop. When the
SHA is no longer locally reachable, `git show <old_sha>` fails inside
`_git_patch_id`, and `detect_change_type` falls back to the
"unknown" classification in the PR's revision-history comment.

Fetch into a stable per-PR ref under `refs/mergify/stack/old-pr-heads/<N>`
(forced refspec, with `--no-write-fetch-head` to avoid touching the
shared FETCH_HEAD pointer). The SHA is then anchored by a real ref
for the lifetime of the patch-id comparison and beyond, so future
runs can compare even after a long gap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Change-Id: Ie5aebff2f4cb939d7f5f448245da5b358361f6ef
Copilot AI review requested due to automatic review settings April 29, 2026 10:13
@jd
Copy link
Copy Markdown
Member Author

jd commented Apr 29, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 fix(stack): anchor old PR head SHAs in local refs for revision history #1314 👈
2 fix(stack): surface fetch_old_pr_heads failures instead of swallowing #1315

@mergify mergify Bot had a problem deploying to Mergify Merge Protections April 29, 2026 10:13 Failure
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 29, 2026

Merge Protections

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

🔴 👀 Review Requirements

Waiting for:

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

🔴 🔎 Reviews

Waiting for:

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

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 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|ui)(?:\(.+\))?:

🟢 📕 PR description

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

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

This PR fixes revision-history change-type detection in stack push by ensuring “old PR head” SHAs remain locally reachable (not just via FETCH_HEAD) so patch-id comparisons don’t degrade to "unknown" after subsequent fetches or garbage collection.

Changes:

  • Fetch refs/pull/<N>/head into stable local refs under refs/mergify/stack/old-pr-heads/<N> using a forced refspec.
  • Add --no-write-fetch-head to avoid mutating the shared FETCH_HEAD.
  • Update stack push tests to assert the new git fetch invocation/refspecs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
mergify_cli/stack/push.py Implements anchored per-PR local refs for old head SHAs and avoids writing FETCH_HEAD.
mergify_cli/tests/stack/test_push.py Updates mocks/assertions to match the new fetch refspec + flags.

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

@mergify mergify Bot requested a review from a team April 29, 2026 10:20
@jd jd closed this Apr 29, 2026
@jd jd deleted the devs/jd/fix/stack-revision-history-fetch-resilience/anchor-old-pr-head-shas-local-refs-revision--e5aebff2 branch April 29, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants