Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Match recreated stacks without unrelated merged history
  • Loading branch information
skarim authored Oct 21, 2026
commit 2002023a3c868974e3d634d24a73faa8148c1856
20 changes: 3 additions & 17 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,24 +538,10 @@ func findLocalStackForRemotePRs(sf *stack.StackFile, prs []*github.PullRequest)
return nil
}

// stackCompositionMatches checks if a local stack's PR numbers match
// the remote stack's PR numbers in the same order.
// stackCompositionMatches ignores merged history that belongs to a previous stack.
func stackCompositionMatches(localStack *stack.Stack, remotePRNumbers []int) bool {
var localPRNumbers []int
for _, b := range localStack.Branches {
if b.PullRequest != nil {
localPRNumbers = append(localPRNumbers, b.PullRequest.Number)
}
}
if len(localPRNumbers) != len(remotePRNumbers) {
return false
}
for i := range localPRNumbers {
if localPRNumbers[i] != remotePRNumbers[i] {
return false
}
}
return true
localPRNumbers := stackPRNumbers(localStack, &github.RemoteStack{PullRequests: remotePRNumbers})
return slicesEqual(localPRNumbers, remotePRNumbers)
}

// handleCompositionConflict prompts the user to resolve a mismatch between
Expand Down
22 changes: 22 additions & 0 deletions cmd/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,28 @@ func TestStackCompositionMatches(t *testing.T) {
remote: []int{10, 11},
matches: true,
},
{
name: "merged history from a previous stack",
local: &stack.Stack{
Branches: []stack.BranchRef{
{Branch: "a", PullRequest: &stack.PullRequestRef{Number: 10, Merged: true}},
{Branch: "b", PullRequest: &stack.PullRequestRef{Number: 11}},
},
},
remote: []int{11},
matches: true,
},
{
name: "merged member of the current stack",
local: &stack.Stack{
Branches: []stack.BranchRef{
{Branch: "a", PullRequest: &stack.PullRequestRef{Number: 10, Merged: true}},
{Branch: "b", PullRequest: &stack.PullRequestRef{Number: 11}},
},
},
remote: []int{10, 11},
matches: true,
},
{
name: "different order",
local: &stack.Stack{
Expand Down