mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
lazygit will offer to push these along with the current branch, so that a rebased stack can be pushed in one go. The commits panel already marks the tips of stacked branches, and this uses the same criterion. A branch is below the given one if its tip is one of the loaded commits of that branch that isn't merged into a main branch. This needs no git command. In whole-graph mode the commit list also contains commits of other branches, but those are marked as merged, so they don't count. Not used yet. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"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.
|
|
//
|
|
// Only the commits passed in are looked at, so a branch whose tip is further
|
|
// down the history than the loaded commits is not found.
|
|
func BranchesBelowInStack(
|
|
commits []*models.Commit,
|
|
branches []*models.Branch,
|
|
branch *models.Branch,
|
|
mainBranches []string,
|
|
) []*models.Branch {
|
|
branchesByTip := map[string][]*models.Branch{}
|
|
for _, other := range branches {
|
|
if other.Name == branch.Name || lo.Contains(mainBranches, other.Name) {
|
|
continue
|
|
}
|
|
branchesByTip[other.CommitHash] = append(branchesByTip[other.CommitHash], other)
|
|
}
|
|
|
|
result := []*models.Branch{}
|
|
for _, commit := range commits {
|
|
if commit.IsTODO() || commit.Status == models.StatusMerged {
|
|
continue
|
|
}
|
|
result = append(result, branchesByTip[commit.Hash()]...)
|
|
}
|
|
|
|
return result
|
|
}
|