mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
feat: git HEAD context
This commit is contained in:
parent
dabc9d4f20
commit
e0adc584e5
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue