Skip to content
Open
Changes from all commits
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
18 changes: 9 additions & 9 deletions cmd/av/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"slices"
"strings"

"emperror.dev/errors"
Expand Down Expand Up @@ -373,21 +372,22 @@ func (vm *remoteAdoptViewModel) initGitFetch(prs []actions.RemotePRInfo, chosenT
}

func (vm *remoteAdoptViewModel) initAdoption(prs []actions.RemotePRInfo, chosenTargets []plumbing.ReferenceName) tea.Cmd {
chosenSet := make(map[string]bool)
for _, target := range chosenTargets {
chosenSet[target.Short()] = true
}
prMap := make(map[string]actions.RemotePRInfo)
for _, prInfo := range prs {
prMap[prInfo.Name] = prInfo
}
var branches []actions.AdoptingBranch
for _, target := range chosenTargets {
idx := slices.IndexFunc(prs, func(prInfo actions.RemotePRInfo) bool {
return prInfo.Name == target.Short()
})
if idx == -1 {
return uiutils.ErrCmd(fmt.Errorf("internal error: failed to find PR info for branch %s", target.Short()))
for i := len(prs) - 1; i >= 0; i-- {
pr := prs[i]
if !chosenSet[pr.Name] {
continue
}
pr := prs[idx]
ab := actions.AdoptingBranch{
Name: target.Short(),
Name: pr.Name,
Parent: pr.Parent,
PullRequest: &pr.PullRequest,
}
Comment on lines 389 to 393
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

There appears to be a bug in how the parent branch is determined. The ab variable is initialized with pr.Parent on line 391. However, the subsequent loop (lines 395-401) modifies pr.Parent to find the correct ancestor if the direct parent's PR is merged or closed. The ab variable that is appended to the branches slice on line 402 does not reflect this change, as it was created before its parent was updated in the loop. This could lead to incorrect parent metadata for the adopted branches.

To resolve this, the initialization of ab should be moved to after the loop that finalizes the parent branch (i.e., after line 401).

Expand Down
Loading