Repository navigation
Conversation
Cache merged PR heads independently of local branch snapshots and compare fallback cutoffs by ancestry. Backfill existing stacks and preserve worktree recovery boundaries.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Core history-rewrite and recovery changes have unresolved correctness concerns and need maintainer validation.
2 open issues
What changed in this PR
This PR addresses #512 by separating GitHub’s merged PR heads from local refs, improving how gh-stack chooses rebase and sync boundaries when local state is stale.
Changes:
- Persist merged PR heads and backfill metadata for existing stacks.
- Validate rebase cutoffs while preserving rollback snapshots and recovery evidence.
- Add regression coverage, offline test defaults, and user documentation.
| File | Description |
|---|---|
internal/stack/stack.go |
Stores merged PR heads separately. |
internal/stack/stack_test.go |
Tests persistence and legacy compatibility. |
internal/stack/schema.json |
Adds the merged-head schema field. |
internal/github/github.go |
Retrieves PR head commit IDs. |
internal/github/github_test.go |
Tests PR-head queries and decoding. |
internal/git/mock_ops.go |
Adds commit-availability mocking. |
internal/git/gitops.go |
Checks commits and handles unavailable fork points. |
internal/git/gitops_test.go |
Tests boundary lookups and worktree failures. |
internal/git/git.go |
Exposes commit checks and documents fork-point behavior. |
internal/config/testing.go |
Stubs GitHub clients by default. |
docs/src/content/docs/reference/cli.md |
Explains cutoff validation and manual recovery. |
cmd/utils.go |
Backfills PR heads and selects validated cutoffs. |
cmd/utils_test.go |
Tests metadata preservation and backfill. |
cmd/sync_test.go |
Adds stale-state and worktree regressions. |
cmd/rebase.go |
Enables boundary resolution without a local merged-parent ref. |
cmd/rebase_test.go |
Adds cutoff, range, and recovery regressions. |
cmd/checkout.go |
Preserves merged heads during import and refresh. |
cmd/checkout_test.go |
Tests imported and refreshed PR-head metadata. |
Review effort: Max
Keep named trunk refs for legacy fork-point discovery and preserve recorded bases already integrated by regular merges.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #512: prevent
rebaseandsyncfrom replaying merged commits when local refs or recorded bases are stale.Functionality and impact
Key areas to review
cmd/utils.go.Testing and verification
go vet ./...go run ./scripts/test -workers 4(full race-enabled suite)go build -o gh-stack .