diff --git a/pkg/gui/branchstack/branchstack.go b/pkg/gui/branchstack/branchstack.go index 97e88cb31..5455fe442 100644 --- a/pkg/gui/branchstack/branchstack.go +++ b/pkg/gui/branchstack/branchstack.go @@ -6,11 +6,11 @@ import ( "github.com/samber/lo" ) -// Returns the branches stacked below the given branch: those whose tip is one -// of the given commits of the branch that hasn't been merged into a main -// branch yet. The branch itself and the main branches are left out. The -// result is in the order in which the tips appear in commits, so the branch -// closest to the given one comes first. +// Returns the branches stacked below the branch with the given name: those +// whose tip is one of the given commits of the branch that hasn't been +// merged into a main branch yet. The branch itself and the main branches +// are left out. The result is in the order in which the tips appear in +// commits, so the branch closest to the given one comes first. // // A commit counts as merged if the remote branch of a main branch contains it // (this is what the commit's status says), but also if the local main branch @@ -23,12 +23,12 @@ import ( func BranchesBelow( commits []*models.Commit, branches []*models.Branch, - branch *models.Branch, + branchName string, mainBranches []string, ) []*models.Branch { branchesByTip := map[string][]*models.Branch{} for _, other := range branches { - if !lo.Contains(mainBranches, other.Name) && other.Name != branch.Name { + if !lo.Contains(mainBranches, other.Name) && other.Name != branchName { branchesByTip[other.CommitHash] = append(branchesByTip[other.CommitHash], other) } } diff --git a/pkg/gui/branchstack/branchstack_test.go b/pkg/gui/branchstack/branchstack_test.go index 90a2ead6c..72bd5cb03 100644 --- a/pkg/gui/branchstack/branchstack_test.go +++ b/pkg/gui/branchstack/branchstack_test.go @@ -141,7 +141,7 @@ func TestBranchesBelow(t *testing.T) { if s.current != nil { branch = s.current } - result := BranchesBelow(s.commits, s.branches, branch, mainBranches) + result := BranchesBelow(s.commits, s.branches, branch.Name, mainBranches) names := lo.Map(result, func(b *models.Branch, _ int) string { return b.Name }) assert.Equal(t, s.expected, names) }) diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 3f4cd4cdd..f4ba5388b 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -129,7 +129,7 @@ func (self *SyncController) pushCurrentBranch(currentBranch *models.Branch) erro // The branches stacked below the current one that have commits to push func (self *SyncController) unpushedBranchesBelow(currentBranch *models.Branch) []*models.Branch { branchesBelow := branchstack.BranchesBelow( - self.c.Model().Commits, self.c.Model().Branches, currentBranch, self.c.UserConfig().Git.MainBranches) + self.c.Model().Commits, self.c.Model().Branches, currentBranch.Name, self.c.UserConfig().Git.MainBranches) return lo.Filter(branchesBelow, func(branch *models.Branch, _ int) bool { // Pushing a branch whose remote branch was deleted would recreate it. @@ -290,7 +290,7 @@ func (self *SyncController) pullCurrentBranch(currentBranch *models.Branch, bran // those that diverged from them only because they were rewritten func (self *SyncController) updatableBranchesBelow(currentBranch *models.Branch) []*models.Branch { branchesBelow := branchstack.BranchesBelow( - self.c.Model().Commits, self.c.Model().Branches, currentBranch, self.c.UserConfig().Git.MainBranches) + self.c.Model().Commits, self.c.Model().Branches, currentBranch.Name, self.c.UserConfig().Git.MainBranches) return lo.Filter(branchesBelow, func(branch *models.Branch, _ int) bool { // Updating a branch that is checked out in another worktree changes