mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
refactor: remove additional git calls
This commit is contained in:
parent
3a86f49b72
commit
667151fe28
|
@ -79,7 +79,7 @@ func (env *environment) getcwd() string {
|
|||
return env.cwd
|
||||
}
|
||||
correctPath := func(pwd string) string {
|
||||
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues
|
||||
// on Windows, and being case sensitive and not consistent and all, this gives silly issues
|
||||
return strings.Replace(pwd, "c:", "C:", 1)
|
||||
}
|
||||
if env.args != nil && *env.args.PWD != "" {
|
||||
|
|
|
@ -268,7 +268,8 @@ func (g *git) getGitHEADContext(ref string) string {
|
|||
}
|
||||
// rebase
|
||||
if g.hasGitFolder("rebase-merge") {
|
||||
origin := g.getGitRefFileSymbolicName("rebase-merge/orig-head")
|
||||
head := g.getGitFileContents("rebase-merge/head-name")
|
||||
origin := strings.Replace(head, "refs/heads/", "", 1)
|
||||
onto := g.getGitRefFileSymbolicName("rebase-merge/onto")
|
||||
step := g.getGitFileContents("rebase-merge/msgnum")
|
||||
total := g.getGitFileContents("rebase-merge/end")
|
||||
|
@ -284,16 +285,19 @@ func (g *git) getGitHEADContext(ref string) string {
|
|||
return fmt.Sprintf("%s%s%s (%s/%s) at %s", icon, branchIcon, origin, step, total, ref)
|
||||
}
|
||||
// merge
|
||||
if g.hasGitFile("MERGE_HEAD") {
|
||||
mergeHEAD := g.getGitRefFileSymbolicName("MERGE_HEAD")
|
||||
if g.hasGitFile("MERGE_MSG") && g.hasGitFile("MERGE_HEAD") {
|
||||
icon := g.props.getString(MergeIcon, "\uE727 ")
|
||||
return fmt.Sprintf("%s%s%s into %s", icon, branchIcon, mergeHEAD, ref)
|
||||
mergeContext := g.getGitFileContents("MERGE_MSG")
|
||||
matches := findNamedRegexMatch(`Merge branch '(?P<head>.*)' into`, mergeContext)
|
||||
if matches != nil && matches["head"] != "" {
|
||||
return fmt.Sprintf("%s%s%s into %s", icon, branchIcon, matches["head"], ref)
|
||||
}
|
||||
}
|
||||
// cherry-pick
|
||||
if g.hasGitFile("CHERRY_PICK_HEAD") {
|
||||
sha := g.getGitRefFileSymbolicName("CHERRY_PICK_HEAD")
|
||||
sha := g.getGitFileContents("CHERRY_PICK_HEAD")
|
||||
icon := g.props.getString(CherryPickIcon, "\uE29B ")
|
||||
return fmt.Sprintf("%s%s onto %s", icon, sha, ref)
|
||||
return fmt.Sprintf("%s%s onto %s", icon, sha[0:6], ref)
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -86,7 +87,7 @@ func setupHEADContextEnv(context *detachedContext) *git {
|
|||
env := new(MockedEnvironment)
|
||||
env.On("hasFolder", "/rebase-merge").Return(context.rebaseMerge)
|
||||
env.On("hasFolder", "/rebase-apply").Return(context.rebaseApply)
|
||||
env.On("getFileContent", "/rebase-merge/orig-head").Return(context.origin)
|
||||
env.On("getFileContent", "/rebase-merge/head-name").Return(context.origin)
|
||||
env.On("getFileContent", "/rebase-merge/onto").Return(context.onto)
|
||||
env.On("getFileContent", "/rebase-merge/msgnum").Return(context.step)
|
||||
env.On("getFileContent", "/rebase-apply/next").Return(context.step)
|
||||
|
@ -94,15 +95,14 @@ func setupHEADContextEnv(context *detachedContext) *git {
|
|||
env.On("getFileContent", "/rebase-apply/last").Return(context.total)
|
||||
env.On("getFileContent", "/rebase-apply/head-name").Return(context.origin)
|
||||
env.On("getFileContent", "/CHERRY_PICK_HEAD").Return(context.cherryPickSHA)
|
||||
env.On("getFileContent", "/MERGE_HEAD").Return(context.mergeHEAD)
|
||||
env.On("getFileContent", "/MERGE_MSG").Return(fmt.Sprintf("Merge branch '%s' into %s", context.mergeHEAD, context.onto))
|
||||
env.On("hasFilesInDir", "", "CHERRY_PICK_HEAD").Return(context.cherryPick)
|
||||
env.On("hasFilesInDir", "", "MERGE_MSG").Return(context.merge)
|
||||
env.On("hasFilesInDir", "", "MERGE_HEAD").Return(context.merge)
|
||||
env.mockGitCommand(context.currentCommit, "rev-parse", "--short", "HEAD")
|
||||
env.mockGitCommand(context.tagName, "describe", "--tags", "--exact-match")
|
||||
env.mockGitCommand(context.origin, "name-rev", "--name-only", "--exclude=tags/*", context.origin)
|
||||
env.mockGitCommand(context.onto, "name-rev", "--name-only", "--exclude=tags/*", context.onto)
|
||||
env.mockGitCommand(context.cherryPickSHA, "name-rev", "--name-only", "--exclude=tags/*", context.cherryPickSHA)
|
||||
env.mockGitCommand(context.mergeHEAD, "name-rev", "--name-only", "--exclude=tags/*", context.mergeHEAD)
|
||||
g := &git{
|
||||
env: env,
|
||||
repo: &gitRepo{
|
||||
|
|
Loading…
Reference in a new issue