mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
refactor(git): branch status as setter
This commit is contained in:
parent
04f841d1b3
commit
930fc2bfcc
|
@ -182,7 +182,7 @@ func (g *git) string() string {
|
||||||
if displayStatus || statusColorsEnabled {
|
if displayStatus || statusColorsEnabled {
|
||||||
g.setGitStatus()
|
g.setGitStatus()
|
||||||
g.setGitHEADContext()
|
g.setGitHEADContext()
|
||||||
g.BranchStatus = g.getBranchStatus()
|
g.setBranchStatus()
|
||||||
} else {
|
} else {
|
||||||
g.Working = &GitStatus{}
|
g.Working = &GitStatus{}
|
||||||
g.Staging = &GitStatus{}
|
g.Staging = &GitStatus{}
|
||||||
|
@ -224,7 +224,8 @@ func (g *git) init(props properties, env environmentInfo) {
|
||||||
g.env = env
|
g.env = env
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *git) getBranchStatus() string {
|
func (g *git) setBranchStatus() {
|
||||||
|
getBranchStatus := func() string {
|
||||||
if g.Ahead > 0 && g.Behind > 0 {
|
if g.Ahead > 0 && g.Behind > 0 {
|
||||||
return fmt.Sprintf(" %s%d %s%d", g.props.getString(BranchAheadIcon, "\u2191"), g.Ahead, g.props.getString(BranchBehindIcon, "\u2193"), g.Behind)
|
return fmt.Sprintf(" %s%d %s%d", g.props.getString(BranchAheadIcon, "\u2191"), g.Ahead, g.props.getString(BranchBehindIcon, "\u2193"), g.Behind)
|
||||||
}
|
}
|
||||||
|
@ -242,6 +243,8 @@ func (g *git) getBranchStatus() string {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
g.BranchStatus = getBranchStatus()
|
||||||
|
}
|
||||||
|
|
||||||
func (g *git) getUpstreamIcon() string {
|
func (g *git) getUpstreamIcon() string {
|
||||||
upstream := replaceAllString("/.*", g.Upstream, "")
|
upstream := replaceAllString("/.*", g.Upstream, "")
|
||||||
|
|
|
@ -486,7 +486,8 @@ func TestGetBranchStatus(t *testing.T) {
|
||||||
Behind: tc.Behind,
|
Behind: tc.Behind,
|
||||||
Upstream: tc.Upstream,
|
Upstream: tc.Upstream,
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.Expected, g.getBranchStatus(), tc.Case)
|
g.setBranchStatus()
|
||||||
|
assert.Equal(t, tc.Expected, g.BranchStatus, tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue