mirror of
https://github.com/aviator-co/av.git
synced 2025-12-30 16:59:49 -06:00
Allow adopting branches on top of local branches (#625)
There's a case where a branch already has been adopted locally, and they want to adopt a new branch on top of that local branch. This change allows that action. While we are here, after a successful adoption, we check out the leaf branch so that the user is in a good state to continue working.
This commit is contained in:
@@ -292,7 +292,10 @@ func (vm *remoteAdoptViewModel) initTreeSelector(prs []actions.RemotePRInfo) tea
|
||||
for _, prInfo := range prs {
|
||||
branch := plumbing.NewBranchReferenceName(prInfo.Name)
|
||||
if prInfo.PullRequest.State == githubv4.PullRequestStateOpen {
|
||||
adoptionTargets = append(adoptionTargets, branch)
|
||||
// Check if the branch is already adopted.
|
||||
if _, ok := vm.db.ReadTx().Branch(prInfo.Name); !ok {
|
||||
adoptionTargets = append(adoptionTargets, branch)
|
||||
}
|
||||
}
|
||||
infos[branch] = actions.BranchTreeInfo{
|
||||
TitleLine: prInfo.Title,
|
||||
@@ -399,7 +402,20 @@ func (vm *remoteAdoptViewModel) initAdoption(prs []actions.RemotePRInfo, chosenT
|
||||
actions.NewAdoptBranchesModel(
|
||||
vm.db,
|
||||
branches,
|
||||
func() tea.Cmd { return tea.Quit },
|
||||
func() tea.Cmd {
|
||||
hasChild := make(map[string]bool)
|
||||
for _, ab := range branches {
|
||||
hasChild[ab.Parent.Name] = true
|
||||
}
|
||||
for _, ab := range branches {
|
||||
if !hasChild[ab.Name] {
|
||||
// Check out the leaf branch. This can fail if the workspace is dirty. In that case, just quietly exit.
|
||||
_, _ = vm.repo.Git(context.Background(), "switch", ab.Name, "--quiet")
|
||||
break
|
||||
}
|
||||
}
|
||||
return tea.Quit
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user