refactor(git): fetch branch name from HEAD file

This commit is contained in:
Jan De Dobbeleer 2021-08-05 06:43:12 +02:00 committed by Jan De Dobbeleer
parent f6c79050d0
commit dff3986258
2 changed files with 7 additions and 1 deletions

View file

@ -406,7 +406,12 @@ func (g *git) getGitRefFileSymbolicName(refFile string) string {
}
func (g *git) getPrettyHEADName() string {
ref := g.getGitCommandOutput("branch", "--show-current")
var ref string
HEAD := g.getGitFileContents("HEAD")
branchPrefix := "ref: refs/heads/"
if strings.HasPrefix(HEAD, branchPrefix) {
ref = strings.TrimPrefix(HEAD, branchPrefix)
}
if ref != "" {
ref = g.truncateBranch(ref)
return fmt.Sprintf("%s%s", g.props.getString(BranchIcon, "\uE0A0"), ref)

View file

@ -105,6 +105,7 @@ func setupHEADContextEnv(context *detachedContext) *git {
env.On("getFileContent", "/REVERT_HEAD").Return(context.revertSHA)
env.On("getFileContent", "/MERGE_MSG").Return(fmt.Sprintf("Merge branch '%s' into %s", context.mergeHEAD, context.onto))
env.On("getFileContent", "/sequencer/todo").Return(context.sequencerTodo)
env.On("getFileContent", "/HEAD").Return(context.branchName)
env.On("hasFilesInDir", "", "CHERRY_PICK_HEAD").Return(context.cherryPick)
env.On("hasFilesInDir", "", "REVERT_HEAD").Return(context.revert)
env.On("hasFilesInDir", "", "MERGE_MSG").Return(context.merge)