Skip to content

Commit

Permalink
refactor: show remote gone icon
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Oct 10, 2020
1 parent 09d4c95 commit 07c985a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion environment.go
Expand Up @@ -48,7 +48,7 @@ func (env *environment) getcwd() string {
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues
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)
}
dir, err := os.Getwd()
Expand Down
7 changes: 5 additions & 2 deletions segment_git.go
Expand Up @@ -41,6 +41,8 @@ const (
BranchAheadIcon Property = "branch_ahead_icon"
//BranchBehindIcon the icon to display when the local branch is behind the remote
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 Property = "local_working_icon"
//LocalStagingIcon the icon to use as the local staging area changes indicator
Expand Down Expand Up @@ -74,7 +76,6 @@ func (g *git) string() string {
if !displayStatus {
return buffer.String()
}
// TODO: Add upstream gone icon
// if ahead, print with symbol
if g.repo.ahead > 0 {
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "+"), g.repo.ahead)
Expand All @@ -83,8 +84,10 @@ func (g *git) string() string {
if g.repo.behind > 0 {
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, "="))
} else if g.repo.upstream == "" {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchGoneIcon, "!="))
}
// if staging, print that part
if g.hasStaging() {
Expand Down
8 changes: 8 additions & 0 deletions segment_git_test.go
Expand Up @@ -261,3 +261,11 @@ func TestParseGitBranchInfoBehindandAhead(t *testing.T) {
assert.Equal(t, "2", got["behind"])
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"])
}

0 comments on commit 07c985a

Please sign in to comment.