Skip to content

Commit a2cd1c3

Browse files
committed
Match recreated stacks without unrelated merged history
1 parent 71f515e commit a2cd1c3

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎cmd/checkout.go‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -538,24 +538,10 @@ func findLocalStackForRemotePRs(sf *stack.StackFile, prs []*github.PullRequest)
538538
return nil
539539
}
540540

541-
// stackCompositionMatches checks if a local stack's PR numbers match
542-
// the remote stack's PR numbers in the same order.
541+
// stackCompositionMatches ignores merged history that belongs to a previous stack.
543542
func stackCompositionMatches(localStack *stack.Stack, remotePRNumbers []int) bool {
544-
var localPRNumbers []int
545-
for _, b := range localStack.Branches {
546-
if b.PullRequest != nil {
547-
localPRNumbers = append(localPRNumbers, b.PullRequest.Number)
548-
}
549-
}
550-
if len(localPRNumbers) != len(remotePRNumbers) {
551-
return false
552-
}
553-
for i := range localPRNumbers {
554-
if localPRNumbers[i] != remotePRNumbers[i] {
555-
return false
556-
}
557-
}
558-
return true
543+
localPRNumbers := stackPRNumbers(localStack, &github.RemoteStack{PullRequests: remotePRNumbers})
544+
return slicesEqual(localPRNumbers, remotePRNumbers)
559545
}
560546

561547
// handleCompositionConflict prompts the user to resolve a mismatch between

‎cmd/checkout_test.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,28 @@ func TestStackCompositionMatches(t *testing.T) {
13411341
remote: []int{10, 11},
13421342
matches: true,
13431343
},
1344+
{
1345+
name: "merged history from a previous stack",
1346+
local: &stack.Stack{
1347+
Branches: []stack.BranchRef{
1348+
{Branch: "a", PullRequest: &stack.PullRequestRef{Number: 10, Merged: true}},
1349+
{Branch: "b", PullRequest: &stack.PullRequestRef{Number: 11}},
1350+
},
1351+
},
1352+
remote: []int{11},
1353+
matches: true,
1354+
},
1355+
{
1356+
name: "merged member of the current stack",
1357+
local: &stack.Stack{
1358+
Branches: []stack.BranchRef{
1359+
{Branch: "a", PullRequest: &stack.PullRequestRef{Number: 10, Merged: true}},
1360+
{Branch: "b", PullRequest: &stack.PullRequestRef{Number: 11}},
1361+
},
1362+
},
1363+
remote: []int{10, 11},
1364+
matches: true,
1365+
},
13441366
{
13451367
name: "different order",
13461368
local: &stack.Stack{

0 commit comments

Comments
 (0)