mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
refactor(git): rename properties to fetch
This commit is contained in:
parent
42f18697fd
commit
1402dcbcfe
|
@ -87,17 +87,17 @@ type git struct {
|
|||
}
|
||||
|
||||
const (
|
||||
// DisplayBranchStatus show branch status or not
|
||||
DisplayBranchStatus Property = "display_branch_status"
|
||||
// DisplayStatus shows the status of the repository
|
||||
DisplayStatus Property = "display_status"
|
||||
// DisplayStashCount show stash count or not
|
||||
DisplayStashCount Property = "display_stash_count"
|
||||
// DisplayWorktreeCount show worktree count or not
|
||||
DisplayWorktreeCount Property = "display_worktree_count"
|
||||
// FetchBranchStatus show branch status or not
|
||||
FetchBranchStatus Property = "fetch_branch_status"
|
||||
// FetchStatus shows the status of the repository
|
||||
FetchStatus Property = "fetch_status"
|
||||
// FetchStashCount show stash count or not
|
||||
FetchStashCount Property = "fetch_stash_count"
|
||||
// FetchWorktreeCount show worktree count or not
|
||||
FetchWorktreeCount Property = "fetch_worktree_count"
|
||||
|
||||
// DisplayUpstreamIcon show or hide the upstream icon
|
||||
DisplayUpstreamIcon Property = "display_upstream_icon"
|
||||
|
||||
// BranchMaxLength truncates the length of the branch name
|
||||
BranchMaxLength Property = "branch_max_length"
|
||||
// BranchIcon the icon to use as branch indicator
|
||||
|
@ -189,7 +189,7 @@ func (g *git) shouldIgnoreRootRepository(rootDir string) bool {
|
|||
|
||||
func (g *git) string() string {
|
||||
statusColorsEnabled := g.props.getBool(StatusColorsEnabled, false)
|
||||
displayStatus := g.props.getBool(DisplayStatus, false)
|
||||
displayStatus := g.getBool(FetchStatus, DisplayStatus, false)
|
||||
if !displayStatus {
|
||||
g.repo.HEAD = g.getPrettyHEADName()
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ func (g *git) string() string {
|
|||
if g.repo.Upstream != "" && g.props.getBool(DisplayUpstreamIcon, false) {
|
||||
g.repo.UpstreamIcon = g.getUpstreamIcon()
|
||||
}
|
||||
if g.props.getBool(DisplayBranchStatus, true) {
|
||||
if g.getBool(FetchBranchStatus, DisplayBranchStatus, true) {
|
||||
g.repo.BranchStatus = g.getBranchStatus()
|
||||
}
|
||||
// use template if available
|
||||
|
@ -281,10 +281,10 @@ func (g *git) setGitStatus() {
|
|||
}
|
||||
}
|
||||
g.repo.HEAD = g.getGitHEADContext(status["local"])
|
||||
if g.props.getBool(DisplayStashCount, false) {
|
||||
if g.getBool(FetchStashCount, DisplayStashCount, false) {
|
||||
g.repo.StashCount = g.getStashContext()
|
||||
}
|
||||
if g.props.getBool(DisplayWorktreeCount, false) {
|
||||
if g.getBool(FetchWorktreeCount, DisplayWorktreeCount, false) {
|
||||
g.repo.WorktreeCount = g.getWorktreeContext()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,15 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// DisplayBranchStatus show branch status or not
|
||||
DisplayBranchStatus Property = "display_branch_status"
|
||||
// DisplayStatus shows the status of the repository
|
||||
DisplayStatus Property = "display_status"
|
||||
// DisplayStashCount show stash count or not
|
||||
DisplayStashCount Property = "display_stash_count"
|
||||
// DisplayWorktreeCount show worktree count or not
|
||||
DisplayWorktreeCount Property = "display_worktree_count"
|
||||
|
||||
// LocalWorkingIcon the icon to use as the local working area changes indicator
|
||||
LocalWorkingIcon Property = "local_working_icon"
|
||||
// LocalStagingIcon the icon to use as the local staging area changes indicator
|
||||
|
@ -35,6 +44,14 @@ const (
|
|||
StatusSeparatorIcon Property = "status_separator_icon"
|
||||
)
|
||||
|
||||
func (g *git) getBool(property, legacyProperty Property, defaultValue bool) bool {
|
||||
_, found := g.props.values[legacyProperty]
|
||||
if found {
|
||||
return g.props.getBool(legacyProperty, defaultValue)
|
||||
}
|
||||
return g.props.getBool(property, defaultValue)
|
||||
}
|
||||
|
||||
func (g *git) renderDeprecatedString(statusColorsEnabled bool) string {
|
||||
if statusColorsEnabled {
|
||||
g.SetStatusColor()
|
||||
|
|
|
@ -756,6 +756,43 @@ func TestGitTemplateString(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "Working and staging area changes with separator",
|
||||
Expected: "main \uF046 +5 ~1 | \uF044 +2 ~3",
|
||||
Template: "{{ .HEAD }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}", //nolint:lll
|
||||
Repo: &Repo{
|
||||
HEAD: "main",
|
||||
Working: &GitStatus{
|
||||
Added: 2,
|
||||
Modified: 3,
|
||||
Changed: true,
|
||||
},
|
||||
Staging: &GitStatus{
|
||||
Added: 5,
|
||||
Modified: 1,
|
||||
Changed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "Working and staging area changes with separator and stash count",
|
||||
Expected: "main \uF046 +5 ~1 | \uF044 +2 ~3 \uf692 3",
|
||||
Template: "{{ .HEAD }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", //nolint:lll
|
||||
Repo: &Repo{
|
||||
HEAD: "main",
|
||||
Working: &GitStatus{
|
||||
Added: 2,
|
||||
Modified: 3,
|
||||
Changed: true,
|
||||
},
|
||||
Staging: &GitStatus{
|
||||
Added: 5,
|
||||
Modified: 1,
|
||||
Changed: true,
|
||||
},
|
||||
StashCount: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "No local changes",
|
||||
Expected: "main",
|
||||
|
@ -777,25 +814,13 @@ func TestGitTemplateString(t *testing.T) {
|
|||
UpstreamIcon: "GitHub",
|
||||
},
|
||||
},
|
||||
{
|
||||
Case: "Branch status",
|
||||
Expected: "from GitHub on main \u21912",
|
||||
Template: "from {{ .UpstreamIcon }} on {{ .HEAD }} {{ .BranchStatus }}",
|
||||
Repo: &Repo{
|
||||
HEAD: "main",
|
||||
Staging: &GitStatus{},
|
||||
Working: &GitStatus{},
|
||||
UpstreamIcon: "GitHub",
|
||||
BranchStatus: "\u21912",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
g := &git{
|
||||
props: &properties{
|
||||
values: map[Property]interface{}{
|
||||
DisplayStatus: true,
|
||||
FetchStatus: true,
|
||||
},
|
||||
},
|
||||
repo: tc.Repo,
|
||||
|
|
Loading…
Reference in a new issue