mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
WIP Show both ahead and behind
This commit is contained in:
parent
6eaece3696
commit
6d2ec43596
3 changed files with 23 additions and 5 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue