mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
feat(git): expose repo name
This commit is contained in:
parent
75cf1b2005
commit
37a4c3eb4e
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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/...)
|
||||
|
|
Loading…
Reference in a new issue