feat(git): expose repo name

This commit is contained in:
Jan De Dobbeleer 2022-07-01 13:14:25 +02:00 committed by Jan De Dobbeleer
parent 75cf1b2005
commit 37a4c3eb4e
3 changed files with 8 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package segments
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/properties"
"oh-my-posh/regex"
"strconv"
@ -50,6 +51,7 @@ type Git struct {
StashCount int
WorktreeCount int
IsWorkTree bool
RepoName string
}
const (
@ -114,6 +116,7 @@ func (g *Git) Enabled() bool {
if !g.shouldDisplay() {
return false
}
g.RepoName = environment.Base(g.env, g.realFolder)
displayStatus := g.props.GetBool(FetchStatus, false)
if displayStatus {
g.setGitStatus()

View file

@ -44,6 +44,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
env.MockGitCommand(fileInfo.Path, "", "describe", "--tags", "--exact-match")
env.On("IsWsl").Return(false)
env.On("HasParentFilePath", ".git").Return(fileInfo, nil)
env.On("PathSeparator").Return("/")
g := &Git{
scm: scm{
env: env,
@ -60,6 +61,7 @@ func TestEnabledInWorkingTree(t *testing.T) {
env.On("HasCommand", "git").Return(true)
env.On("GOOS").Return("")
env.On("IsWsl").Return(false)
env.On("PathSeparator").Return("/")
fileInfo := &environment.FileInfo{
Path: "/dev/folder_worktree/.git",
ParentFolder: "/dev/folder_worktree",
@ -87,6 +89,7 @@ func TestEnabledInSubmodule(t *testing.T) {
env.On("HasCommand", "git").Return(true)
env.On("GOOS").Return("")
env.On("IsWsl").Return(false)
env.On("PathSeparator").Return("/")
fileInfo := &environment.FileInfo{
Path: "/dev/parent/test-submodule/.git",
ParentFolder: "/dev/parent/test-submodule",
@ -115,6 +118,7 @@ func TestEnabledInSeparateGitDir(t *testing.T) {
env.On("HasCommand", "git").Return(true)
env.On("GOOS").Return("")
env.On("IsWsl").Return(false)
env.On("PathSeparator").Return("/")
fileInfo := &environment.FileInfo{
Path: "/dev/parent/test-separate-git-dir/.git",
ParentFolder: "/dev/parent/test-separate-git-dir",

View file

@ -115,6 +115,7 @@ instead of the repo path.
### Properties
- `.RepoName`: `string` - the repo folder name
- `.Working`: `GitStatus` - changes in the worktree (see below)
- `.Staging`: `GitStatus` - staged changes in the work tree (see below)
- `.HEAD`: `string` - the current HEAD context (branch/rebase/merge/...)