diff --git a/segment_git.go b/segment_git.go index 0ce28665..80d8b1eb 100755 --- a/segment_git.go +++ b/segment_git.go @@ -47,6 +47,8 @@ const ( LocalStagingIcon Property = "local_staged_icon" //DisplayStatus shows the status of the repository DisplayStatus Property = "display_status" + //RebaseIcon shows before the rebase context + RebaseIcon Property = "rebase_icon" ) func (g *git) enabled() bool { @@ -121,9 +123,17 @@ func (g *git) getGitOutputForCommand(args ...string) string { } func (g *git) getGitDetachedBranch() string { - ref := g.getGitOutputForCommand("symbolic-ref", "--short", "HEAD") + commit := g.getGitOutputForCommand("rev-parse", "--short", "HEAD") + rebase := g.getGitOutputForCommand("rebase", "--show-current-patch") + if rebase != "" { + return fmt.Sprintf("%s%s", g.props.getString(RebaseIcon, "REBASE: "), commit) + } + ref := g.getGitOutputForCommand("symbolic-ref", "-q", "--short", "HEAD") if ref == "" { - return "unknown" + ref = g.getGitOutputForCommand("describe", "--tags", "--exact-match") + } + if ref == "" { + ref = commit } return ref } diff --git a/segment_git_test.go b/segment_git_test.go index e5f05aa1..d4b1ad8d 100755 --- a/segment_git_test.go +++ b/segment_git_test.go @@ -138,11 +138,11 @@ func TestParseGitBranchInfoBehindandAhead(t *testing.T) { assert.Equal(t, "1", got["ahead"]) } -// func TestGetGitStatus(t *testing.T) { -// env := new(environment) -// writer := gitWriter{ -// env: env, -// } -// writer.getGitStatus() -// assert.NotEmpty(t, writer.repo) -// } +func TestGetGitStatus(t *testing.T) { + env := new(environment) + git := git{ + env: env, + } + git.getGitStatus() + assert.NotEmpty(t, git.repo) +}