feat: git HEAD context

This commit is contained in:
Jan De Dobbeleer 2020-10-07 11:13:42 +02:00 committed by Jan De Dobbeleer
parent dabc9d4f20
commit e0adc584e5
2 changed files with 20 additions and 10 deletions

View file

@ -47,6 +47,8 @@ const (
LocalStagingIcon Property = "local_staged_icon" LocalStagingIcon Property = "local_staged_icon"
//DisplayStatus shows the status of the repository //DisplayStatus shows the status of the repository
DisplayStatus Property = "display_status" DisplayStatus Property = "display_status"
//RebaseIcon shows before the rebase context
RebaseIcon Property = "rebase_icon"
) )
func (g *git) enabled() bool { func (g *git) enabled() bool {
@ -121,9 +123,17 @@ func (g *git) getGitOutputForCommand(args ...string) string {
} }
func (g *git) getGitDetachedBranch() 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 == "" { if ref == "" {
return "unknown" ref = g.getGitOutputForCommand("describe", "--tags", "--exact-match")
}
if ref == "" {
ref = commit
} }
return ref return ref
} }

View file

@ -138,11 +138,11 @@ func TestParseGitBranchInfoBehindandAhead(t *testing.T) {
assert.Equal(t, "1", got["ahead"]) assert.Equal(t, "1", got["ahead"])
} }
// func TestGetGitStatus(t *testing.T) { func TestGetGitStatus(t *testing.T) {
// env := new(environment) env := new(environment)
// writer := gitWriter{ git := git{
// env: env, env: env,
// } }
// writer.getGitStatus() git.getGitStatus()
// assert.NotEmpty(t, writer.repo) assert.NotEmpty(t, git.repo)
// } }