Skip to content

Commit

Permalink
Improved git segment when in detached state or in newly initialized repo
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Aug 23, 2017
1 parent a3bd745 commit d3696af
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions segment-git.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ func parseGitBranchInfo(status []string) map[string]string {
}

func getGitDetachedBranch(p *powerline) string {
command := exec.Command("git", "describe", "--tags", "--always")
command := exec.Command("git", "rev-parse", "--short", "HEAD")
command.Env = gitProcessEnv()
out, err := command.Output()
if err != nil {
return "Error"
command2 := exec.Command("git", "symbolic-ref", "--short", "HEAD")
command2.Env = gitProcessEnv()
out, err := command2.Output()
if err != nil {
return "Error"
} else {
return strings.SplitN(string(out), "\n", 2)[0]
}
} else {
detachedRef := strings.SplitN(string(out), "\n", 2)
return fmt.Sprintf("%s %s", p.symbolTemplates.RepoDetached, detachedRef)
return fmt.Sprintf("%s %s", p.symbolTemplates.RepoDetached, detachedRef[0])
}
}

Expand Down

0 comments on commit d3696af

Please sign in to comment.