refactor: show remote gone icon

This commit is contained in:
Jan De Dobbeleer 2020-10-10 19:16:58 +02:00 committed by Jan De Dobbeleer
parent 09d4c95f15
commit 07c985a680
3 changed files with 14 additions and 3 deletions

View file

@ -48,7 +48,7 @@ func (env *environment) getcwd() string {
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues // on Windows, and being case sentisitive and not consistent and all, this gives silly issues
return strings.Replace(pwd, "c:", "C:", 1) return strings.Replace(pwd, "c:", "C:", 1)
} }
if env.args.PWD != nil && *env.args.PWD != "" { if env.args != nil && *env.args.PWD != "" {
return correctPath(*env.args.PWD) return correctPath(*env.args.PWD)
} }
dir, err := os.Getwd() dir, err := os.Getwd()

View file

@ -41,6 +41,8 @@ const (
BranchAheadIcon Property = "branch_ahead_icon" BranchAheadIcon Property = "branch_ahead_icon"
//BranchBehindIcon the icon to display when the local branch is behind the remote //BranchBehindIcon the icon to display when the local branch is behind the remote
BranchBehindIcon Property = "branch_behind_icon" BranchBehindIcon Property = "branch_behind_icon"
//BranchGoneIcon the icon to use when ther's no remote
BranchGoneIcon Property = "branch_gone_icon"
//LocalWorkingIcon the icon to use as the local working area changes indicator //LocalWorkingIcon the icon to use as the local working area changes indicator
LocalWorkingIcon Property = "local_working_icon" LocalWorkingIcon Property = "local_working_icon"
//LocalStagingIcon the icon to use as the local staging area changes indicator //LocalStagingIcon the icon to use as the local staging area changes indicator
@ -74,7 +76,6 @@ func (g *git) string() string {
if !displayStatus { if !displayStatus {
return buffer.String() return buffer.String()
} }
// TODO: Add upstream gone icon
// if ahead, print with symbol // if ahead, print with symbol
if g.repo.ahead > 0 { if g.repo.ahead > 0 {
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "+"), g.repo.ahead) fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "+"), g.repo.ahead)
@ -83,8 +84,10 @@ func (g *git) string() string {
if g.repo.behind > 0 { if g.repo.behind > 0 {
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchBehindIcon, "-"), g.repo.behind) fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchBehindIcon, "-"), g.repo.behind)
} }
if g.repo.behind == 0 && g.repo.ahead == 0 { if g.repo.behind == 0 && g.repo.ahead == 0 && g.repo.upstream != "" {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchIdenticalIcon, "=")) fmt.Fprintf(buffer, " %s", g.props.getString(BranchIdenticalIcon, "="))
} else if g.repo.upstream == "" {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchGoneIcon, "!="))
} }
// if staging, print that part // if staging, print that part
if g.hasStaging() { if g.hasStaging() {

View file

@ -261,3 +261,11 @@ func TestParseGitBranchInfoBehindandAhead(t *testing.T) {
assert.Equal(t, "2", got["behind"]) assert.Equal(t, "2", got["behind"])
assert.Equal(t, "1", got["ahead"]) assert.Equal(t, "1", got["ahead"])
} }
func TestParseGitBranchInfoNoRemote(t *testing.T) {
g := git{}
branchInfo := "## master"
got := g.parseGitStatusInfo(branchInfo)
assert.Equal(t, "master", got["local"])
assert.Empty(t, got["upstream"])
}