feat: disable git status detail

resolves #93
This commit is contained in:
Jan De Dobbeleer 2020-10-24 19:26:26 +02:00 committed by Jan De Dobbeleer
parent 6ffb8b2d9d
commit f3e46d872b
3 changed files with 66 additions and 8 deletions

View file

@ -42,6 +42,7 @@ Local changes can also shown by default using the following syntax for both the
### Status
- display_status: `boolean` - display the local changes or not - defaults to `true`
- display_status_detail: `boolean` - display the local changes in detail or not - defaults to `true`
- display_stash_count: `boolean` show stash count or not - defaults to `false`
- status_separator_icon: `string` icon/text to display between staging and working area changes - defaults to ` |`
- local_working_icon: `string` - the icon to display in front of the working area changes - defaults to `\uF044`

View file

@ -42,7 +42,7 @@ func (s *gitStatus) string(prefix string, color string) string {
status += stringIfValue(s.untracked, "?")
status += stringIfValue(s.unmerged, "x")
if status != "" {
return fmt.Sprintf(" <%s>%s%s</>", color, prefix, status)
return fmt.Sprintf("<%s>%s%s</>", color, prefix, status)
}
return status
}
@ -70,6 +70,8 @@ const (
LocalStagingIcon Property = "local_staged_icon"
//DisplayStatus shows the status of the repository
DisplayStatus Property = "display_status"
//DisplayStatusDetail shows the detailed status of the repository
DisplayStatusDetail Property = "display_status_detail"
//RebaseIcon shows before the rebase context
RebaseIcon Property = "rebase_icon"
//CherryPickIcon shows before the cherry-pick context
@ -125,7 +127,6 @@ func (g *git) string() string {
if g.props.getBool(StatusColorsEnabled, false) {
g.SetStatusColor()
}
// g.getGitColor()
buffer := new(bytes.Buffer)
// branchName
if g.repo.upstream != "" && g.props.getBool(DisplayUpstreamIcon, false) {
@ -150,15 +151,13 @@ func (g *git) string() string {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchGoneIcon, "\u2262"))
}
if g.repo.staging.changed {
staging := g.repo.staging.string(g.props.getString(LocalStagingIcon, "\uF046"), g.props.getColor(StagingColor, g.props.foreground))
fmt.Fprint(buffer, staging)
fmt.Fprint(buffer, g.getStatusDetailString(g.repo.staging, StagingColor, LocalStagingIcon, " \uF046"))
}
if g.repo.staging.changed && g.repo.working.changed {
fmt.Fprint(buffer, g.props.getString(StatusSeparatorIcon, " |"))
}
if g.repo.working.changed {
working := g.repo.working.string(g.props.getString(LocalWorkingIcon, "\uF044"), g.props.getColor(WorkingColor, g.props.foreground))
fmt.Fprint(buffer, working)
fmt.Fprint(buffer, g.getStatusDetailString(g.repo.working, WorkingColor, LocalWorkingIcon, " \uF044"))
}
if g.props.getBool(DisplayStashCount, false) && g.repo.stashCount != "" {
fmt.Fprintf(buffer, " %s%s", g.props.getString(StashCountIcon, "\uF692"), g.repo.stashCount)
@ -171,6 +170,15 @@ func (g *git) init(props *properties, env environmentInfo) {
g.env = env
}
func (g *git) getStatusDetailString(status *gitStatus, color Property, icon Property, defaultIcon string) string {
prefix := g.props.getString(icon, defaultIcon)
foregroundColor := g.props.getColor(color, g.props.foreground)
if !g.props.getBool(DisplayStatusDetail, true) {
return fmt.Sprintf("<%s>%s</>", foregroundColor, prefix)
}
return status.string(prefix, foregroundColor)
}
func (g *git) getUpstreamSymbol() string {
upstreamRegex := regexp.MustCompile("/.*")
upstream := upstreamRegex.ReplaceAllString(g.repo.upstream, "")

View file

@ -268,7 +268,7 @@ func TestParseGitBranchInfoNoRemote(t *testing.T) {
}
func TestGitStatusUnmerged(t *testing.T) {
expected := " <#123456>working: x1</>"
expected := "<#123456>working: x1</>"
status := &gitStatus{
unmerged: 1,
}
@ -276,7 +276,7 @@ func TestGitStatusUnmerged(t *testing.T) {
}
func TestGitStatusUnmergedModified(t *testing.T) {
expected := " <#123456>working: ~3 x1</>"
expected := "<#123456>working: ~3 x1</>"
status := &gitStatus{
unmerged: 1,
modified: 3,
@ -558,3 +558,52 @@ func TestSetStatusColorForeground(t *testing.T) {
g.SetStatusColor()
assert.Equal(t, expected, g.props.background)
}
func TestGetStatusDetailStringDefault(t *testing.T) {
expected := "<#111111>icon +1</>"
status := &gitStatus{
changed: true,
added: 1,
}
g := &git{
props: &properties{
foreground: "#111111",
},
}
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
}
func TestGetStatusDetailStringNoStatus(t *testing.T) {
expected := "<#111111>icon</>"
status := &gitStatus{
changed: true,
added: 1,
}
g := &git{
props: &properties{
values: map[Property]interface{}{
DisplayStatusDetail: false,
},
foreground: "#111111",
},
}
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
}
func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
expected := "<#123456>icon</>"
status := &gitStatus{
changed: true,
added: 1,
}
g := &git{
props: &properties{
values: map[Property]interface{}{
DisplayStatusDetail: false,
WorkingColor: "#123456",
},
foreground: "#111111",
},
}
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
}