fix: show branch name when upstream gone

resolves #138
This commit is contained in:
Jan De Dobbeleer 2020-11-10 21:35:08 +01:00 committed by Jan De Dobbeleer
parent 96cac5f689
commit 284f2cbccf
2 changed files with 12 additions and 2 deletions

View file

@ -206,7 +206,9 @@ func (g *git) setGitStatus() {
if status["local"] != "" {
g.repo.ahead, _ = strconv.Atoi(status["ahead"])
g.repo.behind, _ = strconv.Atoi(status["behind"])
g.repo.upstream = status["upstream"]
if status["upstream_status"] != "gone" {
g.repo.upstream = status["upstream"]
}
}
g.repo.HEAD = g.getGitHEADContext(status["local"])
g.repo.stashCount = g.getStashContext()
@ -346,7 +348,7 @@ func (g *git) getStashContext() string {
}
func (g *git) parseGitStatusInfo(branchInfo string) map[string]string {
var branchRegex = regexp.MustCompile(`^## (?P<local>\S+?)(\.{3}(?P<upstream>\S+?)( \[(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?])?)?$`)
var branchRegex = regexp.MustCompile(`^## (?P<local>\S+?)(\.{3}(?P<upstream>\S+?)( \[(?P<upstream_status>(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?(gone)?)])?)?$`)
return groupDict(branchRegex, branchInfo)
}

View file

@ -267,6 +267,14 @@ func TestParseGitBranchInfoNoRemote(t *testing.T) {
assert.Empty(t, got["upstream"])
}
func TestParseGitBranchInfoRemoteGone(t *testing.T) {
g := git{}
branchInfo := "## test-branch...origin/test-branch [gone]"
got := g.parseGitStatusInfo(branchInfo)
assert.Equal(t, "test-branch", got["local"])
assert.Equal(t, "gone", got["upstream_status"])
}
func TestGitStatusUnmerged(t *testing.T) {
expected := "<#123456>working: x1</>"
status := &gitStatus{