diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go index 2f9a4dd6e..0002d6b60 100644 --- a/pkg/commands/git_commands/branch_loader.go +++ b/pkg/commands/git_commands/branch_loader.go @@ -125,6 +125,7 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, existingMainBranc return b.Name == branch.Name }); found { branch.BehindBaseBranch.Store(oldBranch.BehindBaseBranch.Load()) + branch.AheadOfBaseBranch.Store(oldBranch.AheadOfBaseBranch.Load()) } } @@ -153,9 +154,12 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, existingMainBranc if len(aheadBehindStr) != 2 { return errors.New("unexpected output from git rev-list") } - if behind, err := strconv.Atoi(aheadBehindStr[1]); err == nil { - branch.BehindBaseBranch.Store(int32(behind)) - renderFunc() + if ahead, err := strconv.Atoi(aheadBehindStr[0]); err == nil { + if behind, err := strconv.Atoi(aheadBehindStr[1]); err == nil { + branch.AheadOfBaseBranch.Store(int32(ahead)) + branch.BehindBaseBranch.Store(int32(behind)) + renderFunc() + } } } } diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go index 9ec699689..5a93228d3 100644 --- a/pkg/commands/models/branch.go +++ b/pkg/commands/models/branch.go @@ -36,6 +36,12 @@ type Branch struct { // determined yet, or up to date with base branch. (We don't need to // distinguish the two, as we don't draw anything in both cases.) BehindBaseBranch atomic.Int32 + + // How far our branch is ahead of its base branch. 0 means either not + // determined yet, or there are no commits on this branch yet, or the branch + // is already merged. (We don't need to distinguish these, as we don't draw + // anything in all these cases.) + AheadOfBaseBranch atomic.Int32 } func (b *Branch) FullRefName() string { diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index 9586672ee..0d7c07590 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -172,11 +172,19 @@ func BranchStatus( } } - if v := branch.BehindBaseBranch.Load(); v != 0 { + ahead := branch.AheadOfBaseBranch.Load() + behind := branch.BehindBaseBranch.Load() + if ahead != 0 || behind != 0 { if result != "" { result += " " } - result += style.FgCyan.Sprintf("↓%d", v) + if ahead != 0 && behind != 0 { + result += style.FgCyan.Sprintf("↓%d↑%d", behind, ahead) + } else if behind != 0 { + result += style.FgCyan.Sprintf("↓%d", behind) + } else { + result += style.FgCyan.Sprintf("↑%d", ahead) + } } return result