diff --git a/src/environment.go b/src/environment.go index 72765b45..2dc18156 100644 --- a/src/environment.go +++ b/src/environment.go @@ -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 != "" { diff --git a/src/segment_git.go b/src/segment_git.go index 9724bef7..91773390 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -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.*)' 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 } diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 140aa2ea..d26dcf6f 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -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{